我正在尝试可视化卷积和胶囊网络的层。可视化代码如下:
layer_outputs = [layer.get_output_at(0) for layer in model.layers[:12]# Extracts the outputs of the top 12 layers
activation_model = models.Model(inputs=model.input, outputs=output_layer) # Creates a model that will return these outputs, given the model input
activations = activation_model.predict(img_tensor)
在这里,img_tensor是形状为(1,28,28,1)的数组。来自mnist数据集的图像。代码的执行将引发错误,如下所示:
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[[[0.0000000e+00],
[0.0000000e+00],
[0.0000000e+00],
[0.0000000e+00],
[0.0000000e+00],
[0.0000000e+00],
[0.0000000e+00],
[0.00000...
由于行activations = activation_model.predict(img_tensor)
导致错误。
有人知道为什么会这样吗?
答案 0 :(得分:0)
您输入的尺寸与模型定义不匹配。
快速调试:将您的输入形状与模型摘要中的输入层形状进行比较。