PatBall1 / detectree2

Python package for automatic tree crown delineation based on the Detectron2 implementation of Mask R-CNN
https://patball1.github.io/detectree2/
MIT License
148 stars 35 forks source link

tutorial.html #77

Closed Joda0515 closed 1 year ago

Joda0515 commented 1 year ago

"If you would just like to make predictions on an orthomosaic with a pre-trained model from the model_garden, skip to part 4."

2.3 and 2.4 are missing from this document. When will they be updated?

Do I need to run this file now if I want to use the pre-trained model provided by the author for image prediction ?

forest-modelling-detectree-v4.ipynb

Thanks again to the author's intention to answer, I wish you a happy life!

PatBall1 commented 1 year ago

@xixi-jodaHuang I can update the tutorial shortly, but in the meantime, you can use the notebook that is in the package. See detectree2/notebooks/colab/predictJB.ipynb This will take you through the process of making predictions.

PatBall1 commented 1 year ago

I can supply you with a pre-trained model too. What kind of area are you predicting on?

Joda0515 commented 1 year ago

Thank you very much!I look forward to your early update. I don't know if there is a pre-trained model for urban areas , if there is, it would be great.

Joda0515 commented 1 year ago

When I was consolidating the predictions, I ran into a problem.

from detectree2.models.outputs import stitch_crowns, clean_crowns folder = "/content/drive/MyDrive/detectree2/data/tilespred/predictions_geo" crowns = stitch_crowns(folder,1)


ValueError Traceback (most recent call last) in 3 folder = "/content/drive/MyDrive/detectree2/data/tilespred/predictions_geo" 4 ----> 5 crowns = stitch_crowns(folder,1)

2 frames /usr/local/lib/python3.7/dist-packages/detectree2/models/outputs.py in (.0) 251 parts = os.path.basename(filename).split("_") 252 --> 253 parts = [int(part) for part in parts[-6:-1]] # type: ignore 254 minx = parts[0] 255 miny = parts[1]

ValueError: invalid literal for int() with base 10: 'Jodagiv'


“Jodagiv” is the tiff file I tested.

But if the name ends with a "_," there will be no error eg: filename = "Prediction_joda_342362_6453876_40_3032633" parts = os.path.basename(filename).split("_") parts = [int(part) for part in parts[-6:-1]] minx = parts[0] miny = parts[1] width = parts[2] buffer = parts[3] crs = parts[4] print((minx, miny, width, buffer, crs))

I'm not sure if that's the problem.

PatBall1 commented 1 year ago

@xixi-jodaHuang that file name should end with .tif. Does it work if you include that?

Joda0515 commented 1 year ago

@xixi-jodaHuang that file name should end with .tif. Does it work if you include that?

img_path = site_path + "/Jodagiv.tif" This is the path to my tif file.This part should be fine.


from detectree2.models.outputs import stitch_crowns, clean_crowns folder = "/content/drive/MyDrive/detectree2/data/tilespred/predictions_geo" crowns = stitch_crowns(folder,1)


After I manually added a "_" to the end of each "geojosn" file name, the code ran.

PatBall1 commented 1 year ago

I think the problem is in the tiling function - I forgot to update it for the new file format. I'll look into that now.

Joda0515 commented 1 year ago

我认为问题出在平稳运行上——我忘记了新的文件格式更新了它。我现在会调查一下。

Thank you very much and look forward to hearing from you.

PatBall1 commented 1 year ago

@Joda0515 I think I have fixed the bug. Hopefully it will work now.