Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: operands could not be broadcast together with shapes (65536,5) (256,256,1) #3

Open
GusRoth opened this issue Apr 30, 2019 · 8 comments

Comments

@GusRoth
Copy link

GusRoth commented Apr 30, 2019

please help me, I dont know how to solve this problem

@filippocastelli
Copy link

@GusRoth Fixing the typo reported in #1 solves the problem bro!

@GusRoth
Copy link
Author

GusRoth commented Jun 30, 2019

@GusRoth Fixing the typo reported in #1 solves the problem bro!

thank you!But the problem is still there....
maybe this is because I don't solves the problem?

predictions_smooth = predict_img_with_smooth_windowing(
input_img,
window_size=window_size,
subdivisions=2, # Minimal amount of overlap for windowing. Must be an even number.
nb_classes=nb_classes,
pred_func=(
lambda img_batch_subdiv: model.predict(img_batch_subdiv)
)
)

I delete the img_to_predict_input directly ,because I don't find the function in the author's code ...
Could you tell me how do you solve this function problem? Or it is ok to just np.expands_dims(img,axis =0 ) to shape(batch_size,h,w,nb_classes)?

@Mahi-Mai
Copy link

Hello @GusRoth . Did you ever figure this out? If so, would you be willing to share your solutions/code?

@fadishaar84
Copy link

@Mahi-Mai @GusRoth @filippocastelli I'm facing the same error, the code throws the same mentioned exception and the proposed solution did not fix it. I appreciate if you could share the solution if you manage to solve it. Thank you.

@Mahi-Mai
Copy link

Mahi-Mai commented Aug 31, 2020

@fadishaar84 Here!

predictions_smooth = predict_img_with_smooth_windowing(
    input_img,
    window_size=window_size,
    subdivisions=2,  # Minimal amount of overlap for windowing. Must be an even number.
    nb_classes=nb_classes,
    pred_func=(
        lambda img_batch_subdiv: model.predict(image_to_neural_input(img_batch_subdiv))
    )
)

Try replacing the value of the last argument (pred_func) with:
(lambda img_batch_subdiv: model.predict(img_batch_subdiv))

I don't know what the heck image_to_neural_input() is supposed to be. It's pretty darned cryptic and it doesn't look like you need it.

Now let me know if you find a good way to speed this process up. On large images it's very slow, but the results are lovely! XD

@bnsreenu
Copy link

To make this code usable here are the changes you need to make:

  1. replace padx to pady in lines 174 and 212where it starts with... for j in range(0, pady_len-window_size+1.......
  2. Change pred_func to... pred_func=(lambda img_batch_subdiv: model.predict((img_batch_subdiv))
  3. Provide input as (IMG_WIDTH, IMG_HEIGHT, NUM_CHANNELS). For example provide your large image input as (2048, 1792, 3). Do not provide input at (Num_images, IMG_WIDTH, IMG_HEIGHT, NUM_CHANNELS). The code does that internally by dividing large image into patches. Make sure you preprocess your images just the way you've done during training.

@ac43934
Copy link

ac43934 commented Jan 5, 2022

In addition to the changes suggested by @bnsreenu,

for RGB images in _window_2D function: replace
np.expand_dims(np.expand_dims(wind, 3), 3)
with
np.expand_dims(np.expand_dims(wind, 1), 1)

@Akwasi-Richie
Copy link

hi @bnsreenu

having an issue and I would be glad if you can help me out. I encounter the error shown below. however, when I print my input image shape is (5000,5000,3)

File "C:\Users\Richmond\AppData\Local\Temp\ipykernel_26400\2710991319.py", line 92, in
lambda img_batch_subdiv: model.predict((img_batch_subdiv))

File "C:\Users\Richmond\AppData\Local\Temp\ipykernel_26400\2283882284.py", line 272, in predict_img_with_smooth_windowing
plt.imshow(prd)

File "C:\Users\Richmond\anaconda3\envs\tensorflow\lib\site-packages\matplotlib_api\deprecation.py", line 456, in wrapper
return func(*args, **kwargs)

File "C:\Users\Richmond\anaconda3\envs\tensorflow\lib\site-packages\matplotlib\pyplot.py", line 2647, in imshow
**kwargs)

File "C:\Users\Richmond\anaconda3\envs\tensorflow\lib\site-packages\matplotlib_api\deprecation.py", line 456, in wrapper
return func(*args, **kwargs)

File "C:\Users\Richmond\anaconda3\envs\tensorflow\lib\site-packages\matplotlib_init_.py", line 1412, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)

File "C:\Users\Richmond\anaconda3\envs\tensorflow\lib\site-packages\matplotlib\axes_axes.py", line 5488, in imshow
im.set_data(X)

File "C:\Users\Richmond\anaconda3\envs\tensorflow\lib\site-packages\matplotlib\image.py", line 716, in set_data
.format(self._A.shape))

TypeError: Invalid shape (5000, 5000, 2) for image data.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants