question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Input 0 is incompatible with layer model

See original GitHub issue

I’m trying the default training (satellite unet) and train went good but when I’m trying to test the model I got the error ValueError: Input 0 is incompatible with layer model: expected shape=(None, 384, 384, 3), found shape=(None, 348, 3)

Here is my test code

model_file = 'model_satellite.h5'
input_shape = (384, 384, 3)

model = satellite_unet(
    input_shape
)

model.load_weights(model_file)
image = np.array(Image.open("test.jpg").resize((348, 348)))
print("shape: ", image.shape)
shape:  (348, 348, 3)
pr_mask = model.predict(image).round()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
karolzakcommented, Nov 8, 2021
image = np.array(Image.open("test.jpg").resize((384, 384)))
print("shape: ", image.shape)
shape: (384, 384, 3)
pr_mask = model.predict(image).round()

Ok, I see your problem. When providing inputs for prediction you need to serve images in batches - if you want to fit just a single image you need to reshape it from (384, 384, 3) to (1, 384, 384, 3)

3reactions
parcodepiecommented, Nov 8, 2021

Indeed it was the problem. Here is the new working code

image = np.array(Image.open("test.jpg").resize((384, 384)))
images_list = []
images_list.append(np.array(image))
x = np.asarray(images_list)
pr_mask = model.predict(x).round()

plt.imshow(
    pr_mask[0]
)
plt.show()

also I’m saving the image to the disk

data = Image.fromarray(np.reshape(pr_mask[0], (384, 384)) )
data = data.convert("L")
data.save('xxx.png')

the model needs more training but it’s a good start

Thanks @karolzak for your time

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input 0 is incompatible with layer lstm_13: expected ndim=3 ...
I solved the problem by making. input size: (95000,360,1) and output size: (95000,22). and changed the input shape to (360,1) in the code ......
Read more >
ValueError:Input 0 of layer sequential is incompatible with the ...
You are getting the error because you are missing the fourth dimension indicating the number of samples. You can use -1 for this...
Read more >
Input 0 is incompatible with layer conv1_1: expected ndim=4 ...
i want train my model with gray levels images but when i want define network this error occur : ValueError: Input 0 is...
Read more >
ValueError: Input 0 of layer sequential is ... - TensorFlow Forum
I am working with the LSTM model and getting this error. ValueError: Input 0 of layer sequential is incompatible with the layer: expected...
Read more >
ValueError: Input 0 of layer sequential_3 is incompatible with ...
ValueError : Input 0 of layer sequential_3 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 180)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found