Comments (12)
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)
from keras-unet.
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
from keras-unet.
Hi @parcodepie
Seems to me you made a mistake when resizing the test image. You used 348x348 instead of 384x384
from keras-unet.
Thanks @karolzak I edited it but it throws another error
Input 0 is incompatible with layer model: expected shape=(None, 384, 384, 3), found shape=(32, 384, 3)
from keras-unet.
Your input array still have a wrong shape. It expects a batch of arrays of size 384x384x3 while you're providing 32 arrays of size 384x3. Something is wrong with your code
from keras-unet.
I'm trying to test only one image what could went wrong?
here is the whole test code
import cv2
import numpy as np
from keras_net.keras_unet.utils import get_patches
from keras_unet.models import satellite_unet
from PIL import Image
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((384, 384)))
print("shape: ", image.shape)
shape: (384, 384, 3)
pr_mask = model.predict(image).round()
cv2.imshow(
"mask: ", pr_mask
)
from keras-unet.
Thanks @karolzak I edited it but it throws another error
Input 0 is incompatible with layer model: expected shape=(None, 384, 384, 3), found shape=(32, 384, 3)
Hi, so how did u fix the issue when you are testing many images instead of just one?
from keras-unet.
hi, i have a same problem ,too
how fix that problem ?
Input 0 is incompatible with layer model: expected shape=(None, 64, 64, 3), found shape=(32, 64, 3) .. . .
from keras-unet.
Hello @hhhhhhhhhhhhhhhhho ! Great username :)
As it was mentioned begore you need to serve images as an array. The solution mentioned above will work:
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()
from keras-unet.
Had the same problem solved it by adding an additional dimension
code before:
for i in range(8):
img = io.imread(TEST_PATH + str(i) + '.png')
print('shape: ', img.shape)
pred = model.predict(img)
prediction = np.squeeze(pred) > .5
plt.imsave(os.path.join(save_path, str(i) + '_predicted.png'), prediction)
Code after:
for i in range(8):
img = io.imread(TEST_PATH + str(i) + '.png')
print('shape: ', img.shape)
img = img[np.newaxis, :, :, :]
pred = model.predict(img)
prediction = np.squeeze(pred) > .5
plt.imsave(os.path.join(save_path, str(i) + '_predicted.png'), prediction)
from keras-unet.
@karolzak I have the same error:
ValueError: Input 0 is incompatible with layer model: expected shape=(None, 9, 4), found shape=(9, 4).
This is my original data shape and I'm trying to generate synthetic data from TimeGAN. When I run the model, got the above error.
from keras-unet.
@tehreemnaqvi Network is expecting batches of inputs of size (9,4). Please read through this thread. Your problem was already answered above.
from keras-unet.
Related Issues (20)
- Early stopping in model HOT 2
- Including multiple classes in satellite unet HOT 1
- ValueError: logits and labels must have the same shape HOT 4
- Loading the model weights HOT 1
- Image Patching -> Image Reconstructing Workflow HOT 3
- input size HOT 2
- loss and iou is nan in satellite_unit HOT 3
- IoU smooth parameters incompatible with input being np.uint8 HOT 1
- Error with the utils file while using RGB images HOT 1
- [New functionality] Adding custom U-Net with 1D convolutions
- Multiclass segmentation with different labels and satellite unet
- satellite_unet custom_objects: '<' not supported between instances of 'function' and 'str' HOT 6
- Loss function return shape HOT 1
- Training on Jetson NX HOT 5
- Is this multi-class segmentation possible? HOT 7
- Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 1, 3), found shape=(None, 3) HOT 1
- Modifying image to accept 8 band satellite image HOT 1
- Semantic segmentation for satellite images
- logits and labels must have the same first dimension HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras-unet.