# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os.path
import sys
import tarfile

import numpy as np
from six.moves import urllib
import tensorflow as tf

from tensorflow.python.platform import gfile
import config

from os import listdir
from os.path import join

DATA_URL = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
BOTTLENECK_TENSOR_NAME = 'pool_3/_reshape:0'
BOTTLENECK_TENSOR_SIZE = 2048
MODEL_INPUT_WIDTH = 299
MODEL_INPUT_HEIGHT = 299
MODEL_INPUT_DEPTH = 3
JPEG_DATA_TENSOR_NAME = 'DecodeJpeg/contents:0'
RESIZED_INPUT_TENSOR_NAME = 'ResizeBilinear:0'
MAX_NUM_IMAGES_PER_CLASS = 2 ** 27 - 1  # ~134M

MODEL_DIR = 'inception'
BOUND_BOX_PATH = config.paths['IMG_DIR_SYNTHETIC']
BOTTLENECK_PATH = config.paths['BOTTLENECK_PATH_SYNTHETIC']


def create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor):
    file_list = []

    file_glob = os.path.join(config.paths['IMG_DIR_SYNTHETIC'], '*.jpg')
    file_list.extend(gfile.Glob(file_glob))

    file_list = sorted(file_list)
    error_list = []
    for i, image in enumerate(file_list):
        #print(image)
        if i % 100 == 0:
            print("{}/{} files processed.".format(i, len(file_list)))
        # getting the name of the training image
        image_name = str(image).split('/')[-1]

        path = os.path.join(BOTTLENECK_PATH, image_name+'.txt')
        try:
            image_data = gfile.FastGFile(image, 'rb').read()
            bottleneck_values = run_bottleneck_on_image(sess, image_data, jpeg_data_tensor, bottleneck_tensor)
            bottleneck_string = ','.join(str(x) for x in bottleneck_values)
            with open(path, 'w') as bottleneck_file:
                bottleneck_file.write(bottleneck_string)
        except:
            error_list.append(image)


    print('ERROR LIST')
    for err in error_list:
        print(err)
    print('end error list')
    print('All bottleneck were create.')


def run_bottleneck_on_image(sess, image_data, image_data_tensor,
                            bottleneck_tensor):
    bottleneck_values = sess.run(bottleneck_tensor, {image_data_tensor: image_data})
    bottleneck_values = np.squeeze(bottleneck_values)
    return bottleneck_values


def maybe_download_and_extract():
    dest_directory = MODEL_DIR
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
    filename = DATA_URL.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not os.path.exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' %(filename, float(count * block_size) / float(total_size)
                                                            * 100.0))
            sys.stdout.flush()

        filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
        print()
        statinfo = os.stat(filepath)
        print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)


def create_inception_graph():
    with tf.Session() as sess:
        model_filename = os.path.join(MODEL_DIR, 'classify_image_graph_def.pb')
        with gfile.FastGFile(model_filename, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            bottleneck_tensor, jpeg_data_tensor, \
            resized_input_tensor = (tf.import_graph_def(graph_def, name='',
                                                        return_elements=[BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME,
                                                                         RESIZED_INPUT_TENSOR_NAME]))
    return sess.graph, bottleneck_tensor, jpeg_data_tensor, resized_input_tensor


def main():
    maybe_download_and_extract()
    graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (create_inception_graph())

    sess = tf.Session()

    create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor)


if __name__ == '__main__':
    main()
54dc65219c82fe82197259f8791d02294b3539bf
<mask token>


def create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor):
    file_list = []
    file_glob = os.path.join(config.paths['IMG_DIR_SYNTHETIC'], '*.jpg')
    file_list.extend(gfile.Glob(file_glob))
    file_list = sorted(file_list)
    error_list = []
    for i, image in enumerate(file_list):
        if i % 100 == 0:
            print('{}/{} files processed.'.format(i, len(file_list)))
        image_name = str(image).split('/')[-1]
        path = os.path.join(BOTTLENECK_PATH, image_name + '.txt')
        try:
            image_data = gfile.FastGFile(image, 'rb').read()
            bottleneck_values = run_bottleneck_on_image(sess, image_data,
                jpeg_data_tensor, bottleneck_tensor)
            bottleneck_string = ','.join(str(x) for x in bottleneck_values)
            with open(path, 'w') as bottleneck_file:
                bottleneck_file.write(bottleneck_string)
        except:
            error_list.append(image)
    print('ERROR LIST')
    for err in error_list:
        print(err)
    print('end error list')
    print('All bottleneck were create.')


def run_bottleneck_on_image(sess, image_data, image_data_tensor,
    bottleneck_tensor):
    bottleneck_values = sess.run(bottleneck_tensor, {image_data_tensor:
        image_data})
    bottleneck_values = np.squeeze(bottleneck_values)
    return bottleneck_values


def maybe_download_and_extract():
    dest_directory = MODEL_DIR
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
    filename = DATA_URL.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not os.path.exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename, 
                float(count * block_size) / float(total_size) * 100.0))
            sys.stdout.flush()
        filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
        print()
        statinfo = os.stat(filepath)
        print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)


<mask token>


def main():
    maybe_download_and_extract()
    graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (
        create_inception_graph())
    sess = tf.Session()
    create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor)


<mask token>

<mask token>


def create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor):
    file_list = []
    file_glob = os.path.join(config.paths['IMG_DIR_SYNTHETIC'], '*.jpg')
    file_list.extend(gfile.Glob(file_glob))
    file_list = sorted(file_list)
    error_list = []
    for i, image in enumerate(file_list):
        if i % 100 == 0:
            print('{}/{} files processed.'.format(i, len(file_list)))
        image_name = str(image).split('/')[-1]
        path = os.path.join(BOTTLENECK_PATH, image_name + '.txt')
        try:
            image_data = gfile.FastGFile(image, 'rb').read()
            bottleneck_values = run_bottleneck_on_image(sess, image_data,
                jpeg_data_tensor, bottleneck_tensor)
            bottleneck_string = ','.join(str(x) for x in bottleneck_values)
            with open(path, 'w') as bottleneck_file:
                bottleneck_file.write(bottleneck_string)
        except:
            error_list.append(image)
    print('ERROR LIST')
    for err in error_list:
        print(err)
    print('end error list')
    print('All bottleneck were create.')


def run_bottleneck_on_image(sess, image_data, image_data_tensor,
    bottleneck_tensor):
    bottleneck_values = sess.run(bottleneck_tensor, {image_data_tensor:
        image_data})
    bottleneck_values = np.squeeze(bottleneck_values)
    return bottleneck_values


def maybe_download_and_extract():
    dest_directory = MODEL_DIR
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
    filename = DATA_URL.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not os.path.exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename, 
                float(count * block_size) / float(total_size) * 100.0))
            sys.stdout.flush()
        filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
        print()
        statinfo = os.stat(filepath)
        print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)


def create_inception_graph():
    with tf.Session() as sess:
        model_filename = os.path.join(MODEL_DIR, 'classify_image_graph_def.pb')
        with gfile.FastGFile(model_filename, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            bottleneck_tensor, jpeg_data_tensor, resized_input_tensor = (tf
                .import_graph_def(graph_def, name='', return_elements=[
                BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME,
                RESIZED_INPUT_TENSOR_NAME]))
    return (sess.graph, bottleneck_tensor, jpeg_data_tensor,
        resized_input_tensor)


def main():
    maybe_download_and_extract()
    graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (
        create_inception_graph())
    sess = tf.Session()
    create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor)


if __name__ == '__main__':
    main()

<mask token>
DATA_URL = (
    'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
    )
BOTTLENECK_TENSOR_NAME = 'pool_3/_reshape:0'
BOTTLENECK_TENSOR_SIZE = 2048
MODEL_INPUT_WIDTH = 299
MODEL_INPUT_HEIGHT = 299
MODEL_INPUT_DEPTH = 3
JPEG_DATA_TENSOR_NAME = 'DecodeJpeg/contents:0'
RESIZED_INPUT_TENSOR_NAME = 'ResizeBilinear:0'
MAX_NUM_IMAGES_PER_CLASS = 2 ** 27 - 1
MODEL_DIR = 'inception'
BOUND_BOX_PATH = config.paths['IMG_DIR_SYNTHETIC']
BOTTLENECK_PATH = config.paths['BOTTLENECK_PATH_SYNTHETIC']


def create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor):
    file_list = []
    file_glob = os.path.join(config.paths['IMG_DIR_SYNTHETIC'], '*.jpg')
    file_list.extend(gfile.Glob(file_glob))
    file_list = sorted(file_list)
    error_list = []
    for i, image in enumerate(file_list):
        if i % 100 == 0:
            print('{}/{} files processed.'.format(i, len(file_list)))
        image_name = str(image).split('/')[-1]
        path = os.path.join(BOTTLENECK_PATH, image_name + '.txt')
        try:
            image_data = gfile.FastGFile(image, 'rb').read()
            bottleneck_values = run_bottleneck_on_image(sess, image_data,
                jpeg_data_tensor, bottleneck_tensor)
            bottleneck_string = ','.join(str(x) for x in bottleneck_values)
            with open(path, 'w') as bottleneck_file:
                bottleneck_file.write(bottleneck_string)
        except:
            error_list.append(image)
    print('ERROR LIST')
    for err in error_list:
        print(err)
    print('end error list')
    print('All bottleneck were create.')


def run_bottleneck_on_image(sess, image_data, image_data_tensor,
    bottleneck_tensor):
    bottleneck_values = sess.run(bottleneck_tensor, {image_data_tensor:
        image_data})
    bottleneck_values = np.squeeze(bottleneck_values)
    return bottleneck_values


def maybe_download_and_extract():
    dest_directory = MODEL_DIR
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
    filename = DATA_URL.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not os.path.exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename, 
                float(count * block_size) / float(total_size) * 100.0))
            sys.stdout.flush()
        filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
        print()
        statinfo = os.stat(filepath)
        print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)


def create_inception_graph():
    with tf.Session() as sess:
        model_filename = os.path.join(MODEL_DIR, 'classify_image_graph_def.pb')
        with gfile.FastGFile(model_filename, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            bottleneck_tensor, jpeg_data_tensor, resized_input_tensor = (tf
                .import_graph_def(graph_def, name='', return_elements=[
                BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME,
                RESIZED_INPUT_TENSOR_NAME]))
    return (sess.graph, bottleneck_tensor, jpeg_data_tensor,
        resized_input_tensor)


def main():
    maybe_download_and_extract()
    graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (
        create_inception_graph())
    sess = tf.Session()
    create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor)


if __name__ == '__main__':
    main()

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os.path
import sys
import tarfile
import numpy as np
from six.moves import urllib
import tensorflow as tf
from tensorflow.python.platform import gfile
import config
from os import listdir
from os.path import join
DATA_URL = (
    'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
    )
BOTTLENECK_TENSOR_NAME = 'pool_3/_reshape:0'
BOTTLENECK_TENSOR_SIZE = 2048
MODEL_INPUT_WIDTH = 299
MODEL_INPUT_HEIGHT = 299
MODEL_INPUT_DEPTH = 3
JPEG_DATA_TENSOR_NAME = 'DecodeJpeg/contents:0'
RESIZED_INPUT_TENSOR_NAME = 'ResizeBilinear:0'
MAX_NUM_IMAGES_PER_CLASS = 2 ** 27 - 1
MODEL_DIR = 'inception'
BOUND_BOX_PATH = config.paths['IMG_DIR_SYNTHETIC']
BOTTLENECK_PATH = config.paths['BOTTLENECK_PATH_SYNTHETIC']


def create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor):
    file_list = []
    file_glob = os.path.join(config.paths['IMG_DIR_SYNTHETIC'], '*.jpg')
    file_list.extend(gfile.Glob(file_glob))
    file_list = sorted(file_list)
    error_list = []
    for i, image in enumerate(file_list):
        if i % 100 == 0:
            print('{}/{} files processed.'.format(i, len(file_list)))
        image_name = str(image).split('/')[-1]
        path = os.path.join(BOTTLENECK_PATH, image_name + '.txt')
        try:
            image_data = gfile.FastGFile(image, 'rb').read()
            bottleneck_values = run_bottleneck_on_image(sess, image_data,
                jpeg_data_tensor, bottleneck_tensor)
            bottleneck_string = ','.join(str(x) for x in bottleneck_values)
            with open(path, 'w') as bottleneck_file:
                bottleneck_file.write(bottleneck_string)
        except:
            error_list.append(image)
    print('ERROR LIST')
    for err in error_list:
        print(err)
    print('end error list')
    print('All bottleneck were create.')


def run_bottleneck_on_image(sess, image_data, image_data_tensor,
    bottleneck_tensor):
    bottleneck_values = sess.run(bottleneck_tensor, {image_data_tensor:
        image_data})
    bottleneck_values = np.squeeze(bottleneck_values)
    return bottleneck_values


def maybe_download_and_extract():
    dest_directory = MODEL_DIR
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
    filename = DATA_URL.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not os.path.exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename, 
                float(count * block_size) / float(total_size) * 100.0))
            sys.stdout.flush()
        filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
        print()
        statinfo = os.stat(filepath)
        print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)


def create_inception_graph():
    with tf.Session() as sess:
        model_filename = os.path.join(MODEL_DIR, 'classify_image_graph_def.pb')
        with gfile.FastGFile(model_filename, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            bottleneck_tensor, jpeg_data_tensor, resized_input_tensor = (tf
                .import_graph_def(graph_def, name='', return_elements=[
                BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME,
                RESIZED_INPUT_TENSOR_NAME]))
    return (sess.graph, bottleneck_tensor, jpeg_data_tensor,
        resized_input_tensor)


def main():
    maybe_download_and_extract()
    graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (
        create_inception_graph())
    sess = tf.Session()
    create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor)


if __name__ == '__main__':
    main()

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os.path
import sys
import tarfile

import numpy as np
from six.moves import urllib
import tensorflow as tf

from tensorflow.python.platform import gfile
import config

from os import listdir
from os.path import join

DATA_URL = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
BOTTLENECK_TENSOR_NAME = 'pool_3/_reshape:0'
BOTTLENECK_TENSOR_SIZE = 2048
MODEL_INPUT_WIDTH = 299
MODEL_INPUT_HEIGHT = 299
MODEL_INPUT_DEPTH = 3
JPEG_DATA_TENSOR_NAME = 'DecodeJpeg/contents:0'
RESIZED_INPUT_TENSOR_NAME = 'ResizeBilinear:0'
MAX_NUM_IMAGES_PER_CLASS = 2 ** 27 - 1  # ~134M

MODEL_DIR = 'inception'
BOUND_BOX_PATH = config.paths['IMG_DIR_SYNTHETIC']
BOTTLENECK_PATH = config.paths['BOTTLENECK_PATH_SYNTHETIC']


def create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor):
    file_list = []

    file_glob = os.path.join(config.paths['IMG_DIR_SYNTHETIC'], '*.jpg')
    file_list.extend(gfile.Glob(file_glob))

    file_list = sorted(file_list)
    error_list = []
    for i, image in enumerate(file_list):
        #print(image)
        if i % 100 == 0:
            print("{}/{} files processed.".format(i, len(file_list)))
        # getting the name of the training image
        image_name = str(image).split('/')[-1]

        path = os.path.join(BOTTLENECK_PATH, image_name+'.txt')
        try:
            image_data = gfile.FastGFile(image, 'rb').read()
            bottleneck_values = run_bottleneck_on_image(sess, image_data, jpeg_data_tensor, bottleneck_tensor)
            bottleneck_string = ','.join(str(x) for x in bottleneck_values)
            with open(path, 'w') as bottleneck_file:
                bottleneck_file.write(bottleneck_string)
        except:
            error_list.append(image)


    print('ERROR LIST')
    for err in error_list:
        print(err)
    print('end error list')
    print('All bottleneck were create.')


def run_bottleneck_on_image(sess, image_data, image_data_tensor,
                            bottleneck_tensor):
    bottleneck_values = sess.run(bottleneck_tensor, {image_data_tensor: image_data})
    bottleneck_values = np.squeeze(bottleneck_values)
    return bottleneck_values


def maybe_download_and_extract():
    dest_directory = MODEL_DIR
    if not os.path.exists(dest_directory):
        os.makedirs(dest_directory)
    filename = DATA_URL.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not os.path.exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' %(filename, float(count * block_size) / float(total_size)
                                                            * 100.0))
            sys.stdout.flush()

        filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
        print()
        statinfo = os.stat(filepath)
        print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)


def create_inception_graph():
    with tf.Session() as sess:
        model_filename = os.path.join(MODEL_DIR, 'classify_image_graph_def.pb')
        with gfile.FastGFile(model_filename, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            bottleneck_tensor, jpeg_data_tensor, \
            resized_input_tensor = (tf.import_graph_def(graph_def, name='',
                                                        return_elements=[BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME,
                                                                         RESIZED_INPUT_TENSOR_NAME]))
    return sess.graph, bottleneck_tensor, jpeg_data_tensor, resized_input_tensor


def main():
    maybe_download_and_extract()
    graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (create_inception_graph())

    sess = tf.Session()

    create_bottleneck_file(sess, jpeg_data_tensor, bottleneck_tensor)


if __name__ == '__main__':
    main()