python - DecodeJpeg Error in Inception V3 Tensorflow -


i novice here don't judge seriuosly. trying create image learing through inception v3 model graph.pb , label.txt files. got error below:

caused op 'decodejpeg', defined at: file "label_image.py", line 153, in <module> tf.app.run(main=main, argv=sys.argv[:1]+unparsed) file "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) file "label_image.py", line 145, in main load_graph(flags.graph) file "label_image.py", line 101, in load_graph tf.import_graph_def(graph_def, name='') file "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 308, in import_graph_def op_def=op_def) file "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op original_op=self._default_original_op, op_def=op_def) file "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__ self._traceback = _extract_stack() invalidargumenterror (see above traceback): invalid jpeg data, size 47258 [[node: decodejpeg = decodejpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_decodejpeg/contents_0)]] 

in cases jpg files work fine, other jpg files throw error above. , solution found via google says this:

with tf.graph().as_default(): image_contents = tf.read_file(image_name) image = tf.image.decode_jpeg(image_contents, channels=3) init_op = tf.initialize_all_tables() tf.session() sess: sess.run(init_op) tmp = sess.run(image) 

but, couldn't me. how can solve problem

my code

from __future__ import absolute_import __future__ import division __future__ import print_function  import argparse import sys  import tensorflow tf import glob, os.path parser = argparse.argumentparser() parser.add_argument(     '--image',     #required=true,     type=str,     default='test2.jpeg',     help='absolute path image file.') parser.add_argument(     '--num_top_predictions',     type=int,     default=5,     help='display many predictions.') parser.add_argument(     '--graph',     #required=true,     type=str,     default='retrained_graph.pb',     help='absolute path graph file (.pb)') parser.add_argument(     '--labels',     #required=true,     type=str,     default='retrained_labels.txt',     help='absolute path labels file (.txt)') parser.add_argument(     '--output_layer',     type=str,     default='final_result:0',     help='name of result operation') parser.add_argument(     '--input_layer',     type=str,     default='decodejpeg/contents:0',     help='name of input operation')   def load_image(filename):   """read in image_data classified."""   return tf.gfile.fastgfile(filename, 'rb').read()   def load_labels(filename):   """read in labels, 1 label per line."""   return [line.rstrip() line in tf.gfile.gfile(filename)]   def load_graph(filename):   """unpersists graph file default graph."""   tf.gfile.fastgfile(filename, 'rb') f:     graph_def = tf.graphdef()     graph_def.parsefromstring(f.read())     tf.import_graph_def(graph_def, name='')   def run_graph(image_data, labels, input_layer_name, output_layer_name,           num_top_predictions):   tf.session() sess:     # feed image_data input graph.     #   predictions contain two-dimensional array, 1     #   dimension represents input image count, , other has     #   predictions per class     softmax_tensor = sess.graph.get_tensor_by_name(output_layer_name)     predictions, = sess.run(softmax_tensor, {input_layer_name: image_data})      # sort show labels in order of confidence     top_k = predictions.argsort()[-num_top_predictions:][::-1]     node_id in top_k:       human_string = labels[node_id]       score = predictions[node_id]       print('%s %.2f)' % (human_string, score*100))      return 0   def main(argv):   """runs inference on image."""   if argv[1:]:     raise valueerror('unused command line args: %s' % argv[1:])    if not tf.gfile.exists(flags.image):     tf.logging.fatal('image file not exist %s', flags.image)    if not tf.gfile.exists(flags.labels):     tf.logging.fatal('labels file not exist %s', flags.labels)    if not tf.gfile.exists(flags.graph):     tf.logging.fatal('graph file not exist %s', flags.graph)    # load image   image_data = load_image(flags.image)    # load labels   labels = load_labels(flags.labels)    # load graph, stored in default session   load_graph(flags.graph)    run_graph(image_data, labels, flags.input_layer, flags.output_layer,         flags.num_top_predictions)   if __name__ == '__main__':   flags, unparsed = parser.parse_known_args()   tf.app.run(main=main, argv=sys.argv[:1]+unparsed) 


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -