在将大小为92200000的数组重塑为形状(-1,100,100,3)时面临问题,它在(-1,100,100)上工作,但



错误:

ValueError                                Traceback (most recent call last)
<ipython-input-56-84713bdbff2f> in <module>()
57 
58 
---> 59 base_model = tf.keras.applications.vgg16.VGG16(weights = 'imagenet', include_top = False, input_shape = (-1,100,100))
60 for layer in base_model.layers:
61   layer.trainable = False
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/applications/imagenet_utils.py in obtain_input_shape(input_shape, default_size, min_size, data_format, require_flatten, weights)
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
368             (input_shape[1] is not None and input_shape[1] < min_size)):
ValueError: The input must have 3 channels; got `input_shape=(-1, 100, 100)`

根据docs的参数input_shape应该是

可选形状元组,仅在include_top为False时指定(否则输入形状必须为(224,224,3)(使用channels_last数据格式)或(3,224,224)(使用channels_first数据格式)。它应该恰好有3个输入通道,宽度和高度应该不小于32。例如(200,200,3)就是一个有效值。

所以使用input_shape=(100, 100, 3)应该可以解决这个问题

您需要创建一个具有三个通道的数组,以将其提供给您的预训练模型。

x = np.repeat(x[..., np.newaxis], 3, -1)

相关内容

最新更新