deeptrees 1.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. deeptrees-1.6.0/LICENSE +13 -0
  2. deeptrees-1.6.0/PKG-INFO +179 -0
  3. deeptrees-1.6.0/README.md +161 -0
  4. deeptrees-1.6.0/deeptrees/__init__.py +43 -0
  5. deeptrees-1.6.0/deeptrees/dataloading/__init__.py +0 -0
  6. deeptrees-1.6.0/deeptrees/dataloading/datamodule.py +337 -0
  7. deeptrees-1.6.0/deeptrees/dataloading/datasets.py +429 -0
  8. deeptrees-1.6.0/deeptrees/dataloading/preprocessing.py +276 -0
  9. deeptrees-1.6.0/deeptrees/datasets/__init__.py +0 -0
  10. deeptrees-1.6.0/deeptrees/datasets/halleDOP20.py +65 -0
  11. deeptrees-1.6.0/deeptrees/inference.py +273 -0
  12. deeptrees-1.6.0/deeptrees/model/__init__.py +0 -0
  13. deeptrees-1.6.0/deeptrees/model/deeptrees_model.py +493 -0
  14. deeptrees-1.6.0/deeptrees/model/distance_model.py +65 -0
  15. deeptrees-1.6.0/deeptrees/model/inference_model.py +29 -0
  16. deeptrees-1.6.0/deeptrees/model/segmentation_model.py +53 -0
  17. deeptrees-1.6.0/deeptrees/modules/__init__.py +0 -0
  18. deeptrees-1.6.0/deeptrees/modules/indices.py +111 -0
  19. deeptrees-1.6.0/deeptrees/modules/losses.py +72 -0
  20. deeptrees-1.6.0/deeptrees/modules/metrics.py +46 -0
  21. deeptrees-1.6.0/deeptrees/modules/polygon_metrics.py +192 -0
  22. deeptrees-1.6.0/deeptrees/modules/polygon_utils.py +67 -0
  23. deeptrees-1.6.0/deeptrees/modules/postprocessing.py +407 -0
  24. deeptrees-1.6.0/deeptrees/modules/rasterize_utils.py +153 -0
  25. deeptrees-1.6.0/deeptrees/modules/traits.py +173 -0
  26. deeptrees-1.6.0/deeptrees/modules/utils.py +1090 -0
  27. deeptrees-1.6.0/deeptrees/pretrained.py +40 -0
  28. deeptrees-1.6.0/deeptrees.egg-info/PKG-INFO +179 -0
  29. deeptrees-1.6.0/deeptrees.egg-info/SOURCES.txt +32 -0
  30. deeptrees-1.6.0/deeptrees.egg-info/dependency_links.txt +1 -0
  31. deeptrees-1.6.0/deeptrees.egg-info/requires.txt +28 -0
  32. deeptrees-1.6.0/deeptrees.egg-info/top_level.txt +1 -0
  33. deeptrees-1.6.0/setup.cfg +4 -0
  34. deeptrees-1.6.0/setup.py +137 -0
@@ -0,0 +1,13 @@
1
+
2
+ ```
3
+ MIT License
4
+
5
+ Copyright (c) 2025 Taimur Khan (UFZ), Caroline Arnold, Harsh Grover (both Helmholtz-Zentrum Hereon and Helmholtz AI)
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ ```
13
+
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.1
2
+ Name: deeptrees
3
+ Version: 1.6.0
4
+ Summary: Tree crown segmentation and analysis in remote sensing imagery with PyTorch
5
+ Home-page: https://codebase.helmholtz.cloud/taimur.khan/DeepTrees
6
+ Author: Taimur Khan, Caroline Arnold, Harsh Grover
7
+ Author-email: taimur.khan@ufz.de
8
+ License: MIT
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: Implementation :: CPython
12
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
13
+ Requires-Python: >=3.10.0
14
+ Description-Content-Type: text/markdown
15
+ Provides-Extra: test
16
+ License-File: LICENSE
17
+
18
+
19
+ <div align="center" style="text-align:center">
20
+ <h1 > DeepTrees 🌳</h1>
21
+ <b>Tree Crown Segmentation and Analysis in Remote Sensing Imagery with PyTorch</b>
22
+ <br/>
23
+ <img src="./static/header.png" alt="DeepTrees" width="300"/>
24
+ <br/>
25
+ </div>
26
+
27
+
28
+ ## Installation
29
+
30
+ To install the package, clone the repository and install the dependencies.
31
+
32
+ ```bash
33
+ git clone https://codebase.helmholtz.cloud/ai-consultants-dkrz/DeepTrees.git
34
+ cd DeepTrees
35
+
36
+ ## create a new conda environment
37
+ conda create --name deeptree
38
+ conda activate deeptree
39
+ conda install -c conda-forge gdal==3.9.2 pip
40
+ pip install -r requirements.txt
41
+ ```
42
+ or from pip.
43
+
44
+ ```bash
45
+ pip install deeptrees
46
+ ```
47
+
48
+ ## Documentation
49
+
50
+ This library is documented using Sphinx. To build the documentation, run the following command.
51
+
52
+ ```bash
53
+ sphinx-apidoc -o docs/source deeptrees
54
+ cd docs
55
+ make html
56
+ ```
57
+
58
+ This will create the documentation in the `docs/build` directory. Open the `index.html` file in your browser to view the documentation.
59
+
60
+ ## Predict on a list of images
61
+
62
+ Run the inference script with the corresponding config file on list of images.
63
+
64
+ ```bash
65
+ from deeptrees import predict
66
+
67
+ predict(image_path=["list of image_paths"], config_path = "config_path")
68
+ ```
69
+
70
+
71
+ ## Scripts
72
+
73
+ ### Preprocessing
74
+
75
+ #### Expected Directory structure
76
+
77
+ The root folder is `/work/ka1176/shared_data/2024-ufz-deeptree/polygon-labelling/`. Sync the folder `tiles` and `labels` with the labeled tiles provided by UFZ. The unlabeled tiles go into `pool_tiles`.
78
+
79
+ ```
80
+ |-- tiles
81
+ | |-- tile_0_0.tif
82
+ | |-- tile_0_1.tif
83
+ | |-- ...
84
+ |-- labels
85
+ | |-- label_tile_0_0.shp
86
+ | |-- label_tile_0_1.shp
87
+ | |-- ...
88
+ |-- pool_tiles
89
+ | |-- tile_4_7.tif
90
+ | |-- tile_4_8.tif
91
+ | |-- ...
92
+ ```
93
+
94
+ Create the new empty directories
95
+
96
+ ```
97
+ |-- masks
98
+ |-- outlines
99
+ |-- dist_trafo
100
+ ```
101
+
102
+ ### Training
103
+
104
+ Adapt your own config file based on the defaults in `train_halle.yaml` as needed. For inspiration for a derived config file for finetuning, check `finetune_halle.yaml`.
105
+
106
+ Run the script like this:
107
+
108
+ ```bash
109
+ python scripts/train.py # this is the default config that trains from scratch
110
+ python scripts/train.py --config-name=finetune_halle # finetune with pretrained model
111
+ python scripts/train.py --config-name=yourconfig # with your own config
112
+ ```
113
+
114
+ To re-generate the ground truth for training, make sure to pass the label directory in `data.ground_truth_labels`. To turn it off, pass `data.ground_truth_labels=null`.
115
+
116
+ You can overwrite individual parameters on the command line, e.g.
117
+
118
+ ```bash
119
+ python scripts/train.py trainer.fast_dev_run=True
120
+ ```
121
+
122
+ To resume training from a checkpoint, take care to pass the hydra arguments in quotes to avoid the shell intercepting the string (pretrained model contains `=`):
123
+
124
+ ```bash
125
+ python scripts/train.py 'model.pretrained_model="Unet-resnet18_epochs=209_lr=0.0001_width=224_bs=32_divby=255_custom_color_augs_k=0_jitted.pt"'
126
+ ```
127
+
128
+ #### Training Logs
129
+
130
+ View the MLFlow logs that were created during training.
131
+
132
+ TODO
133
+
134
+ ### Inference
135
+
136
+ Run the inference script with the corresponding config file. Adjust as needed.
137
+
138
+ ```bash
139
+ python scripts/test.py --config-name=inference_halle
140
+ ```
141
+
142
+
143
+ ## Semantic Versioning
144
+ This reposirotry has auto semantic versionining enabled. To create new releases, we need to merge into the default `finetuning-halle` branch.
145
+
146
+ Semantic Versionining, or SemVer, is a versioning standard for software ([SemVer website](https://semver.org/)). Given a version number MAJOR.MINOR.PATCH, increment the:
147
+
148
+ - MAJOR version when you make incompatible API changes
149
+ - MINOR version when you add functionality in a backward compatible manner
150
+ - PATCH version when you make backward compatible bug fixes
151
+ - Additional labels for pre-release and build metad
152
+
153
+ See the SemVer rules and all possible commit prefixes in the [.releaserc.json](.releaserc.json) file.
154
+
155
+ | Prefix | Explanation | Example |
156
+ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
157
+ | feat | A new feature was implemented as part of the commit, <br>so the [Minor](https://mobiuscode.dev/posts/Automatic-Semantic-Versioning-for-GitLab-Projects/#minor) part of the version will be increased once <br>this is merged to the main branch | feat: model training updated |
158
+ | fix | A bug was fixed, so the [Patch](https://mobiuscode.dev/posts/Automatic-Semantic-Versioning-for-GitLab-Projects/#patch) part of the version will be <br>increased once this is merged to the main branch | fix: fix a bug that causes the user to not <br>be properly informed when a job<br>finishes |
159
+
160
+ The implementation is based on. https://mobiuscode.dev/posts/Automatic-Semantic-Versioning-for-GitLab-Projects/
161
+
162
+
163
+ # License
164
+
165
+ This repository is licensed under the MIT License. For more information, see the [LICENSE.md](LICENSE.md) file.
166
+
167
+ # Cite as
168
+
169
+ ```bib
170
+ @article{khan2025torchtrees,
171
+ author = {Taimur Khan and Caroline Arnold and Harsh Grover},
172
+ title = {DeepTrees: Tree Crown Segmentation and Analysis in Remote Sensing Imagery with PyTorch},
173
+ journal = {arXiv},
174
+ year = {2025},
175
+ archivePrefix = {arXiv},
176
+ eprint = {XXXXX.YYYYY},
177
+ primaryClass = {cs.CV}
178
+ }
179
+ ```
@@ -0,0 +1,161 @@
1
+ <div align="center" style="text-align:center">
2
+ <h1 > DeepTrees 🌳</h1>
3
+ <b>Tree Crown Segmentation and Analysis in Remote Sensing Imagery with PyTorch</b>
4
+ <br/>
5
+ <img src="./static/header.png" alt="DeepTrees" width="300"/>
6
+ <br/>
7
+ </div>
8
+
9
+
10
+ ## Installation
11
+
12
+ To install the package, clone the repository and install the dependencies.
13
+
14
+ ```bash
15
+ git clone https://codebase.helmholtz.cloud/ai-consultants-dkrz/DeepTrees.git
16
+ cd DeepTrees
17
+
18
+ ## create a new conda environment
19
+ conda create --name deeptree
20
+ conda activate deeptree
21
+ conda install -c conda-forge gdal==3.9.2 pip
22
+ pip install -r requirements.txt
23
+ ```
24
+ or from pip.
25
+
26
+ ```bash
27
+ pip install deeptrees
28
+ ```
29
+
30
+ ## Documentation
31
+
32
+ This library is documented using Sphinx. To build the documentation, run the following command.
33
+
34
+ ```bash
35
+ sphinx-apidoc -o docs/source deeptrees
36
+ cd docs
37
+ make html
38
+ ```
39
+
40
+ This will create the documentation in the `docs/build` directory. Open the `index.html` file in your browser to view the documentation.
41
+
42
+ ## Predict on a list of images
43
+
44
+ Run the inference script with the corresponding config file on list of images.
45
+
46
+ ```bash
47
+ from deeptrees import predict
48
+
49
+ predict(image_path=["list of image_paths"], config_path = "config_path")
50
+ ```
51
+
52
+
53
+ ## Scripts
54
+
55
+ ### Preprocessing
56
+
57
+ #### Expected Directory structure
58
+
59
+ The root folder is `/work/ka1176/shared_data/2024-ufz-deeptree/polygon-labelling/`. Sync the folder `tiles` and `labels` with the labeled tiles provided by UFZ. The unlabeled tiles go into `pool_tiles`.
60
+
61
+ ```
62
+ |-- tiles
63
+ | |-- tile_0_0.tif
64
+ | |-- tile_0_1.tif
65
+ | |-- ...
66
+ |-- labels
67
+ | |-- label_tile_0_0.shp
68
+ | |-- label_tile_0_1.shp
69
+ | |-- ...
70
+ |-- pool_tiles
71
+ | |-- tile_4_7.tif
72
+ | |-- tile_4_8.tif
73
+ | |-- ...
74
+ ```
75
+
76
+ Create the new empty directories
77
+
78
+ ```
79
+ |-- masks
80
+ |-- outlines
81
+ |-- dist_trafo
82
+ ```
83
+
84
+ ### Training
85
+
86
+ Adapt your own config file based on the defaults in `train_halle.yaml` as needed. For inspiration for a derived config file for finetuning, check `finetune_halle.yaml`.
87
+
88
+ Run the script like this:
89
+
90
+ ```bash
91
+ python scripts/train.py # this is the default config that trains from scratch
92
+ python scripts/train.py --config-name=finetune_halle # finetune with pretrained model
93
+ python scripts/train.py --config-name=yourconfig # with your own config
94
+ ```
95
+
96
+ To re-generate the ground truth for training, make sure to pass the label directory in `data.ground_truth_labels`. To turn it off, pass `data.ground_truth_labels=null`.
97
+
98
+ You can overwrite individual parameters on the command line, e.g.
99
+
100
+ ```bash
101
+ python scripts/train.py trainer.fast_dev_run=True
102
+ ```
103
+
104
+ To resume training from a checkpoint, take care to pass the hydra arguments in quotes to avoid the shell intercepting the string (pretrained model contains `=`):
105
+
106
+ ```bash
107
+ python scripts/train.py 'model.pretrained_model="Unet-resnet18_epochs=209_lr=0.0001_width=224_bs=32_divby=255_custom_color_augs_k=0_jitted.pt"'
108
+ ```
109
+
110
+ #### Training Logs
111
+
112
+ View the MLFlow logs that were created during training.
113
+
114
+ TODO
115
+
116
+ ### Inference
117
+
118
+ Run the inference script with the corresponding config file. Adjust as needed.
119
+
120
+ ```bash
121
+ python scripts/test.py --config-name=inference_halle
122
+ ```
123
+
124
+
125
+ ## Semantic Versioning
126
+ This reposirotry has auto semantic versionining enabled. To create new releases, we need to merge into the default `finetuning-halle` branch.
127
+
128
+ Semantic Versionining, or SemVer, is a versioning standard for software ([SemVer website](https://semver.org/)). Given a version number MAJOR.MINOR.PATCH, increment the:
129
+
130
+ - MAJOR version when you make incompatible API changes
131
+ - MINOR version when you add functionality in a backward compatible manner
132
+ - PATCH version when you make backward compatible bug fixes
133
+ - Additional labels for pre-release and build metad
134
+
135
+ See the SemVer rules and all possible commit prefixes in the [.releaserc.json](.releaserc.json) file.
136
+
137
+ | Prefix | Explanation | Example |
138
+ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
139
+ | feat | A new feature was implemented as part of the commit, <br>so the [Minor](https://mobiuscode.dev/posts/Automatic-Semantic-Versioning-for-GitLab-Projects/#minor) part of the version will be increased once <br>this is merged to the main branch | feat: model training updated |
140
+ | fix | A bug was fixed, so the [Patch](https://mobiuscode.dev/posts/Automatic-Semantic-Versioning-for-GitLab-Projects/#patch) part of the version will be <br>increased once this is merged to the main branch | fix: fix a bug that causes the user to not <br>be properly informed when a job<br>finishes |
141
+
142
+ The implementation is based on. https://mobiuscode.dev/posts/Automatic-Semantic-Versioning-for-GitLab-Projects/
143
+
144
+
145
+ # License
146
+
147
+ This repository is licensed under the MIT License. For more information, see the [LICENSE.md](LICENSE.md) file.
148
+
149
+ # Cite as
150
+
151
+ ```bib
152
+ @article{khan2025torchtrees,
153
+ author = {Taimur Khan and Caroline Arnold and Harsh Grover},
154
+ title = {DeepTrees: Tree Crown Segmentation and Analysis in Remote Sensing Imagery with PyTorch},
155
+ journal = {arXiv},
156
+ year = {2025},
157
+ archivePrefix = {arXiv},
158
+ eprint = {XXXXX.YYYYY},
159
+ primaryClass = {cs.CV}
160
+ }
161
+ ```
@@ -0,0 +1,43 @@
1
+ __version__ = "v1.6.0"
2
+
3
+ from . import model
4
+ from . import modules
5
+ from . import dataloading
6
+
7
+ from .model.deeptrees_model import TreeCrownDelineationModel
8
+
9
+ from .inference import TreeCrownPredictor
10
+
11
+ from .pretrained import freudenberg2022
12
+
13
+ import os
14
+
15
+
16
+ def predict(image_path: list[str], config_path: str):
17
+ """
18
+ Run tree crown delineation prediction on the provided image paths using the given configuration.
19
+
20
+ Args:
21
+ image_path (list[str]): A list of file paths to the images to be processed.
22
+ config_path (str): The file path to the configuration file for the prediction.
23
+
24
+ Returns:
25
+ None: This function does not return any value. It performs the prediction in-place.
26
+ """
27
+ predictor = TreeCrownPredictor(image_path=image_path, config_path=config_path) # Uses default config path and name
28
+ predictor.predict()
29
+
30
+
31
+ def download_pre_trained_model_weights():
32
+ """
33
+ Downloads the pretrained model weights for the Freudenberg et al. 2022 model.
34
+
35
+ Args:
36
+ download_path (str): The path to save the downloaded model weights to.
37
+ """
38
+
39
+ os.makedirs('./pretrained_models', exist_ok=True)
40
+
41
+ file_name = os.path.join('./pretrained_models', "lUnet-resnet18_epochs=209_lr=0.0001_width=224_bs=32_divby=255_custom_color_augs_k=3_jitted.pt")
42
+
43
+ freudenberg2022(file_name)
File without changes