Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions utils/process_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from tqdm import tqdm

# configure command line interface arguments
flags = tf.app.flags
flags = tf.compat.v1.flags
flags.DEFINE_string('model_dir', '/tmp/imagenet', 'The location of downloaded pre-trained Inception model')
flags.DEFINE_string('image_files', '', 'A glob path of images to process')
flags.DEFINE_integer('clusters', 20, 'The number of clusters to display in the image browser')
Expand Down Expand Up @@ -155,15 +155,15 @@ def create_image_vectors(self):
self.create_tf_graph()

print(' * creating image vectors')
with tf.Session() as sess:
with tf.compat.v1.Session() as sess:
for image_index, image in enumerate(tqdm(self.image_files)):
try:
outfile_name = os.path.basename(image) + '.npy'
out_path = join(self.output_dir, 'image_vectors', outfile_name)
if os.path.exists(out_path) and not self.rewrite_image_vectors:
continue
# save the penultimate inception tensor/layer of the current image
with tf.gfile.FastGFile(image, 'rb') as f:
with tf.compat.v2.io.gfile.GFile(image, 'rb') as f:
data = {'DecodeJpeg/contents:0': f.read()}
feature_tensor = sess.graph.get_tensor_by_name('pool_3:0')
feature_vector = np.squeeze( sess.run(feature_tensor, data) )
Expand Down Expand Up @@ -202,8 +202,8 @@ def create_tf_graph(self):
'''
print(' * creating tf graph')
graph_path = join(FLAGS.model_dir, 'classify_image_graph_def.pb')
with tf.gfile.FastGFile(graph_path, 'rb') as f:
graph_def = tf.GraphDef()
with tf.compat.v1.gfile.GFile(graph_path, 'rb') as f:
graph_def = tf.compat.v1.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')

Expand Down Expand Up @@ -491,4 +491,4 @@ def main(*args, **kwargs):
PixPlot(image_glob)

if __name__ == '__main__':
tf.app.run()
tf.compat.v1.app.run()