Open panbo-bridge opened 9 months ago
The error says that the model received 4 channels, but expects 5. The readme.md file from the zip file containing the weights mentions that the model was trained RGBI images plus NDVI (=5 channels) and at the bottom it mentions an example inference call that looks like this:
./inference.py -i input_file.tif -o output_file.sqlite -m ~/models/*jitted* -w 224 --ndvi --min-dist 10 --sigma 2 -l 0.4 -b 0.05 -s 0.21 --div 255 --rescale-ndvi --save-prediction ~/intermediate_output --sigmoid
This does a few things: 1) divides the 8 bit RGBI input image by 255 2) it computes the NDVI on the fly 3) it rescales the NDVI to 0..1 4) it applies sigmoid to the network output 5) sets the input image size to 224 6) sets the minimum distance for tree crowns to 10 pixels, which affects over / undersegmentation 7) sets some thresholds for crown detection that control the size of resulting crowns (l and b parameters, look at the help via inference.py -h) 8) saves the network output from which the crown polygons are computed (useful for debugging) 9) sets the polygon simplification to 0.21m, so that the resulting files are smaller; delineating single pixels is most of the time overkill
You could further specify the index of your red and nir band for NDVI computation via --red and --nir.
Hope that helps!
Thanks to the fact that I have been able to run the program, but probably because I don't have RGBI images, I didn't get the desired results using RGBA
Hmmm, currently I haven't trained any model on RGB only and not time to retrain one. What you could do however, is to load the model and remove the fourth and fifth channel from the first conv layer weights. Then it works with RGB, but I don't know to which quality. Feel free to close the issue if that fixes your problems.
Hi, my images is in png format. The annotations are organized in ms coco format and stored in json files. How can I preprocess the data correctly?
Would make more sense to open another issue for this, but currently coco format is not supported because the rasterization algorithm relies on georeferenced data. However, generating the training data from coco format should be straight forward as well. You basically need three annotations per image: the masks, the outlines and the distance transform. So you can load the coco annotations for one image, compute the mask, compute the outlines, then subtract the outlines from the masks and compute the distance transform (from scipy.ndimage import distance_transform_edt). Then save all three and you're good to go. The rasterization scripts can serve as rough guidance on how I did it with shapely polygons.
Thank you for your guidance. If I still have questions about this topic, I will open a new issue and upload your suggestions in it.
Here are my input parameters "-i","input/2021-09-02-sbl-z3-rgb-cog.tif","-o","result","-m","models/Unet-resnet18_epochs=209_lr=0.0001_width=224_bs=32_divby=255_custom_color_augs_k=0_jitted.pt" This is my error message 发生异常: RuntimeError (note: full exception trace is shown but execution is paused at: _run_module_as_main) The following operation failed in the TorchScript interpreter. Traceback of TorchScript, serialized code (most recent call last): File "code/torch/treecrowndelineation/model/tcd_model.py", line 12, in forward dist_model = self.dist_model seg_model = self.seg_model _0 = (seg_model).forward(img, )