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

`get_filenames` concatenates two absolute paths #96

Closed ancazugo closed 1 year ago

ancazugo commented 1 year ago

The get_filenames() function of detectree2.models.train uses glob method to filter the files with a .png extension in the directory given as parameter. The glob method returns the absolute path of all the files. Then, the function uses os.path.join() to concatenate the directory and the glob result; hence the result is a non-existent path.

For instance, if the following chunk is run:

in_dir = Path("drive/Shareddrives/detectree2_Cambridge/data/Cambridge/tiles_0.25m_160_20_0_samp")
tiles_dir = in_dir / 'tiles'

files = get_filenames(str(tiles_dir) + '/')

This is the result:

[{'file_name': 'drive/Shareddrives/detectree2_Cambridge/data/Cambridge/tiles_0.25m_160_20_0_samp/drive/Shareddrives/detectree2_Cambridge/data/Cambridge/tiles_0.25m_160_20_0_samp/160_20_0CityCentre_2017_32630_712515_5789228_160_20_32630.png'},
 {'file_name': 'drive/Shareddrives/detectree2_Cambridge/data/Cambridge/tiles_0.25m_160_20_0_samp/drive/Shareddrives/detectree2_Cambridge/data/Cambridge/tiles_0.25m_160_20_0_samp/160_20_0CityCentre_2017_32630_713155_5788908_160_20_32630.png'}]

So the path is duplicated, which causes the predict_on_data() function to give NULL results because it couldn't read the png files.

PatBall1 commented 1 year ago

For the path to be considered absolute it should be preceded with a /. So in your case "/drive/Shareddrives/detectree2_Cambridge/data/Cambridge/tiles_0.25m_160_20_0_samp". We should implement a function that is robust to this though.