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

Operands could not be broadcast together with shapes (13, 128, 13) (13, 128, 128) #10

Open
CatalinVulcan opened this issue Jul 22, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@CatalinVulcan
Copy link

I'm trying to use the pre-trained model for prediction using the following command:

python dsen2cr_main.py --predict model_SARcarl.hdf5

But I'm getting the following error. Do you have any idea why this is?

Traceback (most recent call last):
File "dsen2cr_main.py", line 198, in
run_dsen2cr(args.predict_file, args.resume_file)
File "dsen2cr_main.py", line 145, in run_dsen2cr
include_sar_input=include_sar_input)
File "C:\Users\Catalin\Desktop\cloud removal\dsen2cr_network.py", line 52, in DSen2CR_model
x = Add()([x, input_opt])
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 824, in call
self._maybe_build(inputs)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 2146, in _maybe_build
self.build(input_shapes)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\utils\tf_utils.py", line 306, in wrapper
output_shape = fn(instance, input_shape)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\layers\merge.py", line 111, in build
output_shape = self._compute_elemwise_op_output_shape(output_shape, shape)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\layers\merge.py", line 82, in _compute_elemwise_op_output_shape
'together with shapes ' + str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (13, 128, 13) (13, 128, 128)

@ameraner
Copy link
Owner

Hi @CatalinVulcan . Thanks for reporting the issue. I would suspect an issue where the dimensions are in the wrong order (the bands dimension being the third dimension instead of the first). Could you check the input shapes that you pass to the model

model, shape_n = DSen2CR_model(input_shape,
?
Is this line also still active in your code:
K.set_image_data_format('channels_first')
?

@CatalinVulcan
Copy link
Author

Thank you for your reply. It had to do with the version of Numpy. But in the end, I couldn't make it work due to library versioning and compatibility.

Using

conda install -c conda-forge python=3.7 tensorflow-gpu=1.15.0 keras=2.2.4 numpy scipy rasterio pydot graphviz h5py,

resulted in installing some package versions that gave errors when running the code. I tried changing the versions, but every time I changed one, other errors and incompatibilities appeared until I reached a point I simply couldn't solve.

For input, I used images from the dataset mentioned in the README. It might help to include 3 images in the repository as well, along with the appropriate datasetfilelist.csv. This might make things simpler.

@ameraner
Copy link
Owner

Ah, yeah. Unfortunately I have no means atm to try to update the code for newer package versions. If you ever get it running, feel free to open a PR or propose changes! Also, good point about the images..

@ameraner ameraner mentioned this issue Aug 3, 2023
@ameraner ameraner added the bug Something isn't working label Dec 28, 2023
@ameraner
Copy link
Owner

@animecomico has reported in #6 (comment) that this works:

conda create -y -n dsen2_cr_v1 python=3.7.0
conda activate dsen2_cr_v1
conda install numpy=1.17.5
pip install tensorflow==1.13.2
pip install keras==2.2.4
pip install matplotlib==2.1.1
pip install rasterio
pip install pydot
pip install h5py
pip install graphviz
pip install scipy
pip install protobuf==3.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants