1

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)?

2
  • 1
    In the last line, just directly write data.reshape((1, 150, 150, 3)) Commented Apr 20, 2021 at 5:18
  • @SreekantShenoy thank you a lot. As I understood, the firtst value here (None, 150, 150, 3) is equal to ((1, 150, 150, 3)) Commented Apr 20, 2021 at 5:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.