【发布时间】:2021-04-20 04:58:07
【问题描述】:
我有一个 CNN 模型,输入图像大小为(150, 150)。我想为predict 函数(tensorflow)提供类似数组的数据,如下所示:
fig = plt.figure(figsize=(1.5, 1.5))
plt.plot(time_values, signal_values, '-o', c='r')
plt.axis('off')
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
当我尝试时:
CNN_model.predict(data)
我收到一个错误:
WARNING:tensorflow:Model was constructed with shape (None, 150, 150, 3) for input Tensor("input_1:0", shape=(None, 150, 150, 3), dtype=float32), but it was called on an input with incompatible shape (None, 150, 3).
Traceback (most recent call last):
为什么我的形状是(None, 150, 3),而不是(None, 150, 150, 3)?
【问题讨论】:
-
最后一行直接写
data.reshape((1, 150, 150, 3)) -
@SreekantShenoy 非常感谢。据我了解,这里的第一个值 (None, 150, 150, 3) 等于 ((1, 150, 150, 3))
标签: python tensorflow neural-network conv-neural-network