Reputation: 59
I have a CNN model, which input image size is (150, 150)
. I want to feed array-like data for predict
function (tensorflow) like this:
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,))
And when I try:
CNN_model.predict(data)
I get an error:
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):
Why my shape is (None, 150, 3)
, but not (None, 150, 150, 3)
?
Upvotes: 1
Views: 1039
Reputation: 328
Just add a new dimension to your array data
:
data = data[None, :]
Its shape will then be (1, 150, 150, 3)
, as expected by tensorflow.
Upvotes: 1