Tensorflow object detection API之InvalidArgumentError: image_size must contain 3 elements[4]

出現錯誤:

INFO:tensorflow:global step 4192: loss = 2.4735 (1.707 sec/step)

INFO:tensorflow:Error reported to Coordinator: <class tensorflow.python.framework.errors_impl.InvalidArgumentError>, image_size must contain 3 elements[4]

[[Node: cond_2/RandomCropImage/sample_distorted_bounding_box/SampleDistortedBoundingBoxV2 = SampleDistortedBoundingBoxV2[T=DT_INT32, area_range=[0.1, 1], aspect_ratio_range=[0.5, 2], max_attempts=100, seed=0, seed2=0, use_image_if_no_bounding_boxes=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](cond_2/RandomCropImage/Shape, cond_2/RandomCropImage/ExpandDims, cond_2/RandomCropImage/PruneNonOverlappingBoxes/Const)]]

INFO:tensorflow:global step 4193: loss = 2.9267 (2.034 sec/step)

INFO:tensorflow:Finished training! Saving model to disk.

Traceback (most recent call last):

File "train.py", line 167, in <module>

app.run()

File "D:Anacondalibsite-packages ensorflowpythonplatformapp.py", line 126, in run

_sys.exit(main(argv))

File "train.py", line 163, in main

worker_job_name, is_chief, FLAGS.train_dir)

File "D:python3models-master
esearchobject_detection rainer.py", line 399, in train

saver=saver)

File "D:Anacondalibsite-packages ensorflowcontribslimpythonslimlearning.py", line 784, in train

ignore_live_threads=ignore_live_threads)

File "D:Anacondalibsite-packages ensorflowpython rainingsupervisor.py", line 828, in stop

ignore_live_threads=ignore_live_threads)

File "D:Anacondalibsite-packages ensorflowpython rainingcoordinator.py", line 389, in join

six.reraise(*self._exc_info_to_raise)

File "D:Anacondalibsite-packagessix.py", line 693, in reraise

raise value

File "D:Anacondalibsite-packages ensorflowpython rainingqueue_runner_impl.py", line 252, in _run

enqueue_callable()

File "D:Anacondalibsite-packages ensorflowpythonclientsession.py", line 1249, in _single_operation_run

self._call_tf_sessionrun(None, {}, [], target_list, None)

File "D:Anacondalibsite-packages ensorflowpythonclientsession.py", line 1420, in _call_tf_sessionrun

status, run_metadata)

File "D:Anacondalibsite-packages ensorflowpythonframeworkerrors_impl.py", line 516, in __exit__

c_api.TF_GetCode(self.status.status))

tensorflow.python.framework.errors_impl.InvalidArgumentError: image_size must contain 3 elements[4]

[[Node: cond_2/RandomCropImage/sample_distorted_bounding_box/SampleDistortedBoundingBoxV2 = SampleDistortedBoundingBoxV2[T=DT_INT32, area_range=[0.1, 1], aspect_ratio_range=[0.5, 2], max_attempts=100, seed=0, seed2=0, use_image_if_no_bounding_boxes=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](cond_2/RandomCropImage/Shape, cond_2/RandomCropImage/ExpandDims, cond_2/RandomCropImage/PruneNonOverlappingBoxes/Const)]]

出錯原因:很可能是有些圖片不是RGB格式的

解決方法:把訓練集和測試集中不是RGB格式的圖片以及對應的xml文件刪除掉,重新生成tfrecord數據,下面給出判斷圖片是否是RGB格式的python代碼

from PIL import Image import os path = ./images/ #path是圖片所在的文件夾for file in os.listdir(path): extension = file.split(.)[-1] if extension == jpg: fileLoc = path+file img = Image.open(fileLoc) if img.mode != RGB: print(file+, +img.mode)

這樣,問題應該就能得到解決了


推薦閱讀:

吊炸天的CNNs,這是我見過最詳盡的圖解!(上)
斯科德M802立式人臉動態識別終端
15分鐘用 Keras 和 Supervisely 搞定車牌識別技術
黑暗中工作的人臉識別技術

TAG:目標檢測 | 圖像識別 |