解决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]

报错信息
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=

欢迎大家交流学习,任何问题都可以留言
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值