Tensorflow Invalid JPEG data or crop window, data size 之一

在使用Tensorflow进行图像学习时,遇到错误提示'Invalid JPEG data or crop window, data size',原因是Tensorflow不支持progressive类型的JPEG图片。解决方法是将这些图片转换为baseline格式,可以通过OpenCV进行转换。参考文章《OpenCV将JPEG中的progressive类型转换成baseline类型》来解决此问题。" 110690953,10295080,Python多进程获取子进程返回值:Pool与Process应用,"['Python编程', '多进程', '并发处理']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用Tensorflow学习图片的时候会遇到:
《OpenCV将JPEG中的progressive类型转换成baseline类型》

Traceback (most recent call last):
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1327, in _do_call
    return fn(*args)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1312, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1420, in _call_tf_sessionrun
    status, run_metadata)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 516, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid JPEG data or crop window, data size 32768
	 [[Node: DecodeJpeg_1 = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJPGInput_0_0)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "retrain.py", line 382, in create_bottleneck_file
    resized_input_tensor, bottleneck_tensor)
  File "retrain.py", line 314, in run_bottleneck_on_image
    {image_data_tensor: image_data})
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 905, in run
    run_metadata_ptr)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1140, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
    run_metadata)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid JPEG data or crop window, data size 32768
	 [[Node: DecodeJpeg_1 = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJPGInput_0_0)]]

Caused by op 'DecodeJpeg_1', defined at:
  File "retrain.py", line 1366, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "retrain.py", line 1049, in main
    model_info['input_std'])
  File "retrain.py", line 995, in add_jpeg_decoding
    decoded_image = tf.image.decode_jpeg(jpeg_data, channels=input_depth)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_image_ops.py", line 944, in decode_jpeg
    name=name)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3290, in create_op
    op_def=op_def)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1654, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Invalid JPEG data or crop window, data size 32768
	 [[Node: DecodeJpeg_1 = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJPGInput_0_0)]]


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "retrain.py", line 1366, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "retrain.py", line 1180, in main
    f.write('\n'.join(image_lists.keys()) + '\n')
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1545, in __exit__
    self._default_graph_context_manager.__exit__(exec_type, exec_value, exec_tb)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 5086, in get_controller
    yield g
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 4896, in get_controller
    yield default
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 5086, in get_controller
    yield g
  File "retrain.py", line 1065, in main
    bottleneck_tensor, FLAGS.architecture)
  File "retrain.py", line 488, in cache_bottlenecks
    resized_input_tensor, bottleneck_tensor, architecture)
  File "retrain.py", line 430, in get_or_create_bottleneck
    bottleneck_tensor)
  File "retrain.py", line 385, in create_bottleneck_file
    str(e)))
RuntimeError: Error during processing file train/hentai/a2407693-2cb4-4254-8b0d-28daa00be68c.jpg (Invalid JPEG data or crop window, data size 32768
	 [[Node: DecodeJpeg_1 = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJPGInput_0_0)]]

Caused by op 'DecodeJpeg_1', defined at:
  File "retrain.py", line 1366, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "retrain.py", line 1049, in main
    model_info['input_std'])
  File "retrain.py", line 995, in add_jpeg_decoding
    decoded_image = tf.image.decode_jpeg(jpeg_data, channels=input_depth)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_image_ops.py", line 944, in decode_jpeg
    name=name)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3290, in create_op
    op_def=op_def)
  File "/home/king/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1654, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Invalid JPEG data or crop window, data size 32768
	 [[Node: DecodeJpeg_1 = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJPGInput_0_0)]]

这个是什么原因呢?

 file OCR-eng.jpg  QR4.jpeg 
OCR-eng.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, progressive , precision 8, 2639x1169, frames 3
QR4.jpeg:  JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline , precision 8, 640x480, frames 3

Tensorflow 不认识progressive的图片,需要转化成baseline格式的图片。转换方式就是抬头写的那篇文章。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值