jonathanventura / urban-tree-detection

MIT License
60 stars 12 forks source link

shape mismatch #2

Closed PradeepYLN closed 5 months ago

PradeepYLN commented 1 year ago

Thank you for providing the script with pre-trained weights. I am attempting to test on my own RGB data, but I encountered the following error. could you please assist me in resolving this issue?

python scripts/inference.py input_images output pretrained same error for python scripts/test.py data.hdf5 pretrained

Traceback (most recent call last): File "/urban-tree-detection/scripts/inference.py", line 69, in main() File "/urban-tree-detection/scripts/inference.py", line 54, in main training_model.load_weights(weights_path) File "/.cache/pypoetry/virtualenvs/indices-forestry-_Wq4v6x3-py3.9/lib/python3.9/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "/.cache/pypoetry/virtualenvs/indices-forestry-_Wq4v6x3-py3.9/lib/python3.9/site-packages/keras/src/backend.py", line 4361, in _assign_value_to_variable variable.assign(value) ValueError: Cannot assign value to variable ' sfa_net/vgg/base_conv/conv2d/kernel:0': Shape mismatch.The variable shape (3, 3, 3, 64), and the assigned value shape (3, 3, 5, 64) are incompatible.

ARTenshi commented 11 months ago

Hi,

I had the same problem using three-channel images as input to the inference model. I solved it with OpenCV:

import cv2

rgb = cv2.imread('input/jpg/my_image.jpg', 1) rgba = cv2.cvtColor(rgb, cv2.COLOR_RGB2RGBA) cv2.imwrite('input/tiff/my_image.tif', rgba)

jonathanventura commented 11 months ago

@PradeepYLN You would need to add the flag --bands RGB to use the inference script on RGB imagery. But, the pre-trained model was made using NAIP imagery which is four channel (red,green,blue,near-infrared). So it can't really be applied to three-channel imagery. You would need to re-train the model on RGB imagery.

@ARTenshi your solution would make the code run but the near-infrared channel would be filled with 255, I believe, so it may not give accurate results.

jonathanventura commented 5 months ago

I fixed the code to better support working with RGB data, and added a pre-trained RGB model as well. Hope you find it helpful!