Keras 无效参数:必须为占位符张量';vgg16_输入4';使用数据类型float和shape[?,32,32,3]

Keras 无效参数:必须为占位符张量';vgg16_输入4';使用数据类型float和shape[?,32,32,3],keras,deep-learning,conv-neural-network,tf.keras,vgg-net,Keras,Deep Learning,Conv Neural Network,Tf.keras,Vgg Net,我发现以下错误 InvalidArgumentError:发现2个根错误。(0)无效参数: 必须使用 数据类型float和shape[?,32,32,3][{{{node vgg16_input_4}}]] [[dense_6/Softmax/_1775]](1)无效参数:必须输入 带有数据类型float和 形状[?,32,32,3][{{node vgg16_input_4}}]]0成功 操作。忽略0个派生错误 和下面的代码 def show_result(n): samples =

我发现以下错误

InvalidArgumentError:发现2个根错误。(0)无效参数: 必须使用 数据类型float和shape[?,32,32,3][{{{node vgg16_input_4}}]]
[[dense_6/Softmax/_1775]](1)无效参数:必须输入 带有数据类型float和 形状[?,32,32,3][{{node vgg16_input_4}}]]0成功 操作。忽略0个派生错误

和下面的代码

def show_result(n):

    samples = []
    for i in range(n):
        original_img = x_test[i]
        print('original_img->',original_img.shape)

        img_array = np.expand_dims(original_img, 0)
        #img_array = original_img


        print('img_arrray->', img_array.shape)
        #tf.image.convert_image_dtype(img_array, dtype=tf.float16, saturate=False)

        get_output = K.function([model.layers[0].input], [model.layers[-3].output, model.layers[-1].output])
        [conv_outputs, predictions] = get_output([img_array])

        conv_outputs = conv_outputs[0, :, :, :]
        class_weights = model.layers[-1].get_weights()[0]

        cam = np.zeros(dtype = np.float32, shape = conv_outputs.shape[0:2])
图像的形状是

原始图像->(32,32,3)图像->(1,32,32,3)


您的img_数组具有形状(1,32,32,3),而get_output([img_数组])您再次将img_数组添加到列表中,这将生成形状(1,1,32,32,3),那么我应该更改为哪一行?有点混乱尝试:获取_输出(img_数组)而不是获取_输出([img_数组])
model = models.Sequential()

base_model = VGG16(include_top = False, input_shape=(32, 32, 3))
base_model.layers.pop()
model.add(base_model)
model.add(layers.ZeroPadding2D(padding=(1,1)))
model.add(layers.Conv2D(filters=1024, kernel_size=(3,3),activation='relu'))
model.add(layers.GlobalAveragePooling2D())
model.add(layers.Dense(10,activation='softmax'))