解决tensorflow.python.framework.errors_impl.InvalidArgumentError: image_size must contain 3 elements[4]
报错信息
tensorflow.python.framework.errors_impl.InvalidArgumentError: image_size must contain 3 elements[4]
[[Node: ssd_preprocessing_train/distorted_bounding_box_crop/sample_distorted_bounding_box/SampleDistortedBoundingBoxV2 = SampleDistortedBoundingBoxV2[T=DT_INT32,
area_range=[0.1, 1], aspect_ratio_range=[0.6, 1.67], max_attempts=200, seed=0, seed2=0, use_image_if_no_bounding_boxes=true, _device="/job:localhost/replica:0/task:0/devic
e:CPU:0"](ssd_preprocessing_train/distorted_bounding_box_crop/Shape, ssd_preprocessing_train/ExpandDims_1, ssd_preprocessing_train/distorted_bounding_box_crop/sample_disto
rted_bounding_box/SampleDistortedBoundingBoxV2/min_object_covered)]]
解决办法
# encoding:utf-8
from PIL import Image
import os
import matplotlib.pyplot as plt
def get_not_rgb_images(rootdir):
list = os.listdir(rootdir)
l = len(list)
count = 0
for i in range(0, len(list)):
filename = os.path.join(rootdir, list[i])
# print(filename)
if os.path.isfile(filename):
img = Image.open(filename)
pixels = img.getpixel((0, 0))
if type(pixels) == int:
print('单通道:' + filename)
count += 1
print('The ', i, 'st pic:', count, '/', l, '\r')
# img = Image.open(imgName)
img = img.convert('RGB')
img.save(filename)
elif type(pixels) == tuple:
if len(pixels) != 3:
print('非RGB的多通道:' + filename)
count += 1
print('The ', i, 'st pic:', count, '/', l, '\r')
img = img.convert('RGB')
img.save(filename)
else:
get_not_rgb_images(filename)
if __name__ == '__main__':
rootdir = './VOC2007/JPEGImages' # 您图片所在的文件夹
get_not_rgb_images(rootdir)
=原文地址https://blog.csdn.net/siriusli1981/article/details/88793097=
欢迎大家交流学习,任何问题都可以留言