Tensorflow ValueError:输入必须有3个通道;得到'input_shape=(2002001)`

Tensorflow ValueError:输入必须有3个通道;得到'input_shape=(2002001)`,tensorflow,keras,deep-learning,transfer-learning,vgg-net,Tensorflow,Keras,Deep Learning,Transfer Learning,Vgg Net,我正在尝试将迁移学习与VGG16结合使用。我正在使用Keras。但我在上面有错误 vgg = vgg16.VGG16(include_top=False, weights='imagenet', input_shape=(IMG_SIZE, IMG_SIZE, 1)) 有什么问题吗 注:IMG\u尺寸=200 错误的痕迹是 --------------------------------------------------------------------------- ValueError

我正在尝试将迁移学习与VGG16结合使用。我正在使用Keras。但我在上面有错误

vgg = vgg16.VGG16(include_top=False, weights='imagenet', input_shape=(IMG_SIZE, IMG_SIZE, 1))
有什么问题吗

注:
IMG\u尺寸
=200

错误的痕迹是

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-1b17094c93e2> in <module>
      3 import keras
      4 
----> 5 vgg = vgg16.VGG16(include_top=False, weights='imagenet', input_shape=(IMG_SIZE, IMG_SIZE, 1))
      6 
      7 output = vgg.layers[-1].output

c:\users\hiteshsom\documents\deepanshu_q2\env\lib\site-packages\tensorflow\python\keras\applications\vgg16.py in VGG16(include_top, weights, input_tensor, input_shape, pooling, classes, classifier_activation)
    124                      ' as true, `classes` should be 1000')
    125   # Determine proper input shape
--> 126   input_shape = imagenet_utils.obtain_input_shape(
    127       input_shape,
    128       default_size=224,

c:\users\hiteshsom\documents\deepanshu_q2\env\lib\site-packages\tensorflow\python\keras\applications\imagenet_utils.py in obtain_input_shape(input_shape, default_size, min_size, data_format, require_flatten, weights)
    363           raise ValueError('`input_shape` must be a tuple of three integers.')
    364         if input_shape[-1] != 3 and weights == 'imagenet':
--> 365           raise ValueError('The input must have 3 channels; got '
    366                            '`input_shape=' + str(input_shape) + '`')
    367         if ((input_shape[0] is not None and input_shape[0] < min_size) or

ValueError: The input must have 3 channels; got `input_shape=(200, 200, 1)`
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在里面
3进口干酪
4.
---->5 vgg=vgg16.vgg16(包括_top=False,weights='imagenet',输入_shape=(IMG_大小,IMG_大小,1))
6.
7输出=vgg.layers[-1]。输出
vgg16中的c:\users\hitessom\documents\deepanshu\u q2\env\lib\site packages\tensorflow\python\keras\applications\vgg16.py(包括顶部、权重、输入张量、输入形状、池、类、分类器激活)
124“如果是真的,`classes`应该是1000')
125#确定正确的输入形状
-->126 input_shape=imagenet_utils.QUOTE_input_shape(
127输入U形,
128默认_大小=224,
c:\users\hitessom\documents\deepanshu\u q2\env\lib\site packages\tensorflow\python\keras\applications\imagenet\u utils.py在获取输入形状中(输入形状、默认大小、最小大小、数据格式、需要展平、权重)
363 raise VALUETERROR(“'input_shape'必须是三个整数的元组”。)
364如果输入_形[-1]!=3且权重='imagenet':
-->365 raise VALUERROR('输入必须有3个通道;got'
366'`input_shape='+str(input_shape)+'`
367如果((输入形状[0]不是无且输入形状[0]<最小大小)或
ValueError:输入必须有3个通道;获取'input_shape=(200200,1)`

您不能使用带有单通道图像的图像净重。这可能会解决您的问题:

vgg = vgg16.VGG16(include_top=False, weights=None, input_shape=(IMG_SIZE, IMG_SIZE, 1))

(200,200,1)与(200,200,3)不同,但我的输入图像大小是(200,200,1)。我有灰度图像。您使用的是在ImageNet上预训练的模型,即颜色数据(3通道)。您不能将此模型与单通道数据一起使用。这是否回答了您的问题?