Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not a JPEG issue #9786

Closed
santle opened this issue May 9, 2017 · 14 comments
Closed

Not a JPEG issue #9786

santle opened this issue May 9, 2017 · 14 comments
Assignees
Labels
type:docs-bug Document issues

Comments

@santle
Copy link

santle commented May 9, 2017

bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir /Training_image
Looking for images in 'non-human'
Looking for images in 'human'
Creating bottleneck at /tmp/bottleneck/non-human/Data__negatives_jpeg_cr_night_512x384_cr_night_512x384_rCR_m26_a10_d2005-04-07_t22-38_wN.jpg.txt
2017-05-09 01:56:48.890091: W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
Not a JPEG file: starts with 0x89 0x50
Traceback (most recent call last):
File "/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 1105, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 844, in main
bottleneck_tensor)
File "bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 469, in cache_bottlenecks
jpeg_data_tensor, bottleneck_tensor)
File "bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 417, in get_or_create_bottleneck
bottleneck_tensor)
File "bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 376, in create_bottleneck_file
raise RuntimeError('Error during processing file %s' % image_path)
RuntimeError: Error during processing file /Training_images/non-human/Data__negatives_jpeg_cr_night_512x384

How to fix this?

@girving
Copy link
Contributor

girving commented May 9, 2017

I'm guessing the problem that is your image is...drumroll...not a jpeg.

It's probably a png. I recommend using tf.image.decode_image if you have a dataset that mixes png and jpeg. I will fix the error message to explicitly say this.

@girving girving self-assigned this May 9, 2017
@girving girving added the type:docs-bug Document issues label May 9, 2017
@girving
Copy link
Contributor

girving commented May 9, 2017

@petewarden Any objections to me changing the example to tf.image.decode_image? Too many people have png-jpegs.

@petewarden
Copy link
Contributor

@girving No, this seems like a good change to me, thanks!

@girving
Copy link
Contributor

girving commented May 15, 2017

decode_jpeg now handles pngs without comment.

@Mohit-Ak
Copy link

Mohit-Ak commented Oct 23, 2017

Here is a python script to identify those fault jpg images in a directory.
`

import glob 
import os 
import re 
import logging 
import traceback    
filelist=glob.glob("/path/to/*.jpg")
for file_obj in filelist:
  try:
	
		jpg_str=os.popen("file \""+str(file_obj)+"\"").read()
		if (re.search('PNG image data', jpg_str, re.IGNORECASE)) or (re.search('Png patch', jpg_str, re.IGNORECASE)):
			print("Deleting jpg as it contains png encoding - "+str(file_obj))
			os.system("rm \""+str(file_obj)+"\"")
  except Exception as e:
	logging.error(traceback.format_exc())
print("Cleaning jps done")`

@girving
Copy link
Contributor

girving commented Oct 23, 2017

@Mohit-Ak Note that you don't need to do this anymore; Tensorflow's decode_jpeg handles PNGs.

@Mohit-Ak
Copy link

But I faced the same issue when I used the Object Detection API. This happens on the Cloud Training when it reads the ".record" file.

I don't know the place where the object detection API uses it but it still has the issue. I can give you the logs if you want.

@girving
Copy link
Contributor

girving commented Oct 23, 2017

Ah, the Object Detection API may be parsing the jpeg outside of TensorFlow. Not much TF can do about that.

@Mohit-Ak
Copy link

Here are the cloud logs. Just for the reference. We could do a ctrl+F for "JPEG" and find a lot of matches.

21:44:47.081 - Not a JPEG file: starts with 0x89 0x50
Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 198, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 194, in main worker_job_name, is_chief, FLAGS.train_dir) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 296, in train saver=saver) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/learning.py", line 804, in train raise File "/usr/lib/python2.7/contextlib.py", line 35, in exit self.gen.throw(type, value, traceback) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 960, in managed_session self.stop(close_summary_writer=close_summary_writer) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 788, in stop stop_grace_period_secs=self._stop_grace_secs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/coordinator.py", line 386, in join six.reraise(*self._exc_info_to_raise) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/queue_runner_impl.py", line 234, in _run sess.run(enqueue_op) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 767, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 965, in _run feed_dict_string, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1015, in _do_run target_list, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1035, in _do_call raise type(e)(node_def, op, message) InvalidArgumentError: Invalid JPEG data, size 881303 [[Node: case/If_0/DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:master/replica:0/task:0/cpu:0"](case/If_0/DecodeJpeg/Switch:1, ^case/Assert/AssertGuard/Merge)]] Caused by op u'case/If_0/DecodeJpeg', defined at: File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 198, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 194, in main worker_job_name, is_chief, FLAGS.train_dir) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 184, in train data_augmentation_options) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 59, in _create_input_queue tensor_dict = create_tensor_dict_fn() File "/root/.local/lib/python2.7/site-packages/object_detection/builders/input_reader_builder.py", line 63, in build return tf_example_decoder.TfExampleDecoder().decode(string_tensor) File "/root/.local/lib/python2.7/site-packages/object_detection/data_decoders/tf_example_decoder.py", line 121, in decode tensors = decoder.decode(serialized_example, items=keys) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/data/tfexample_decoder.py", line 418, in decode outputs.append(handler.tensors_to_item(keys_to_tensors)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/data/tfexample_decoder.py", line 302, in tensors_to_item return self._decode(image_buffer, image_format) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/data/tfexample_decoder.py", line 345, in _decode pred_fn_pairs, default=default_decoder, exclusive=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2973, in case case_seq = _build_case() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2955, in build_case name="If%d" % i) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1738, in cond orig_res, res_t = context_t.BuildCondBranch(fn1) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1639, in BuildCondBranch r = fn() File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/data/tfexample_decoder.py", line 323, in decode_jpg return image_ops.decode_jpeg(image_buffer, self._channels) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_image_ops.py", line 345, in decode_jpeg dct_method=dct_method, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2327, in create_op original_op=self._default_original_op, op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1226, in init self._traceback = _extract_stack() InvalidArgumentError (see above for traceback): Invalid JPEG data, size 881303 [[Node: case/If_0/DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:master/replica:0/task:0/cpu:0"](case/If_0/DecodeJpeg/Switch:1, ^case/Assert/AssertGuard/Merge)]]

@girving
Copy link
Contributor

girving commented Oct 23, 2017

So that's either an older version of TensorFlow, a different of corruption (not related to PNGs), or a different bug.

@Mohit-Ak
Copy link

But I cloned it just yesterday and it got fixed after running the above script.

@girving
Copy link
Contributor

girving commented Oct 23, 2017

Then it's a different bug. Care to diagnose why the format classification logic isn't working? https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/decode_image_op.cc#L156

@Kiesh
Copy link

Kiesh commented Mar 16, 2020

@ Mohit-Ak
I am using your code but error occurs 'file' is not recognized as an internal or external command,

@mihaimaruseac
Copy link
Collaborator

Locking as this is a bug solved over 2 years ago. Please open a new issue, filling in all of the template

@tensorflow tensorflow locked as resolved and limited conversation to collaborators Mar 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:docs-bug Document issues
Projects
None yet
Development

No branches or pull requests

6 participants