pointtree 0.0.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.
- pointtree-0.0.0/LICENSE +21 -0
- pointtree-0.0.0/PKG-INFO +114 -0
- pointtree-0.0.0/README.md +33 -0
- pointtree-0.0.0/pyproject.toml +81 -0
- pointtree-0.0.0/setup.cfg +4 -0
- pointtree-0.0.0/setup.py +3 -0
- pointtree-0.0.0/src/pointtree/__init__.py +0 -0
- pointtree-0.0.0/src/pointtree/config/__init__.py +5 -0
- pointtree-0.0.0/src/pointtree/config/_config.py +19 -0
- pointtree-0.0.0/src/pointtree/evaluation/__init__.py +7 -0
- pointtree-0.0.0/src/pointtree/evaluation/_metrics.py +233 -0
- pointtree-0.0.0/src/pointtree/evaluation/_time_tracker.py +45 -0
- pointtree-0.0.0/src/pointtree/evaluation/_timer.py +29 -0
- pointtree-0.0.0/src/pointtree/instance_segmentation/__init__.py +7 -0
- pointtree-0.0.0/src/pointtree/instance_segmentation/_instance_segmentation_algorithm.py +232 -0
- pointtree-0.0.0/src/pointtree/instance_segmentation/_multi_stage_algorithm.py +1218 -0
- pointtree-0.0.0/src/pointtree/instance_segmentation/_priority_queue.py +107 -0
- pointtree-0.0.0/src/pointtree/instance_segmentation/_utils.py +45 -0
- pointtree-0.0.0/src/pointtree/io/__init__.py +19 -0
- pointtree-0.0.0/src/pointtree/io/_base_point_cloud_reader.py +88 -0
- pointtree-0.0.0/src/pointtree/io/_base_point_cloud_writer.py +90 -0
- pointtree-0.0.0/src/pointtree/io/_csv_reader.py +83 -0
- pointtree-0.0.0/src/pointtree/io/_csv_writer.py +76 -0
- pointtree-0.0.0/src/pointtree/io/_las_reader.py +103 -0
- pointtree-0.0.0/src/pointtree/io/_las_writer.py +145 -0
- pointtree-0.0.0/src/pointtree/io/_point_cloud_io_data.py +19 -0
- pointtree-0.0.0/src/pointtree/io/_point_cloud_reader.py +46 -0
- pointtree-0.0.0/src/pointtree/io/_point_cloud_writer.py +45 -0
- pointtree-0.0.0/src/pointtree/operations/__init__.py +9 -0
- pointtree-0.0.0/src/pointtree/operations/_knn_search.py +277 -0
- pointtree-0.0.0/src/pointtree/operations/_make_labels_consecutive.py +64 -0
- pointtree-0.0.0/src/pointtree/operations/_pack_batch.py +61 -0
- pointtree-0.0.0/src/pointtree/operations/_ravel_index.py +121 -0
- pointtree-0.0.0/src/pointtree/operations/_voxel_downsampling.py +170 -0
- pointtree-0.0.0/src/pointtree/visualization/__init__.py +7 -0
- pointtree-0.0.0/src/pointtree/visualization/_color_palette.py +39 -0
- pointtree-0.0.0/src/pointtree/visualization/_color_point_cloud.py +107 -0
- pointtree-0.0.0/src/pointtree/visualization/_hex_to_rgb.py +29 -0
- pointtree-0.0.0/src/pointtree/visualization/_save_tree_map.py +85 -0
- pointtree-0.0.0/src/pointtree.egg-info/PKG-INFO +114 -0
- pointtree-0.0.0/src/pointtree.egg-info/SOURCES.txt +42 -0
- pointtree-0.0.0/src/pointtree.egg-info/dependency_links.txt +1 -0
- pointtree-0.0.0/src/pointtree.egg-info/requires.txt +34 -0
- pointtree-0.0.0/src/pointtree.egg-info/top_level.txt +1 -0
pointtree-0.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Josafat-Mattias Burmeister
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pointtree-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pointtree
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: A Python Package for Individual Tree Segmentation in 3D Point Clouds.
|
|
5
|
+
Author-email: Josafat-Mattias Burmeister <burmeister@uni-potsdam.de>
|
|
6
|
+
Maintainer-email: Josafat-Mattias Burmeister <burmeister@uni-potsdam.de>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024 Josafat-Mattias Burmeister
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/ai4trees/pointtree
|
|
30
|
+
Project-URL: Documentation, https://ai4trees.github.io/pointtree/
|
|
31
|
+
Project-URL: Repository, https://github.com/ai4trees/pointtree.git
|
|
32
|
+
Project-URL: Issues, https://github.com/ai4trees/pointtree/issues
|
|
33
|
+
Project-URL: Changelog, https://ai4trees.github.io/pointtree/changelog
|
|
34
|
+
Keywords: tree,point cloud,segmentation
|
|
35
|
+
Classifier: Development Status :: 4 - Beta
|
|
36
|
+
Classifier: Intended Audience :: Science/Research
|
|
37
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
38
|
+
Classifier: Programming Language :: Python
|
|
39
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
45
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
46
|
+
Requires-Python: >=3.9
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
License-File: LICENSE
|
|
49
|
+
Requires-Dist: numba
|
|
50
|
+
Requires-Dist: numba-kdtree
|
|
51
|
+
Requires-Dist: numpy
|
|
52
|
+
Requires-Dist: pandas
|
|
53
|
+
Requires-Dist: pyclesperanto-prototype
|
|
54
|
+
Requires-Dist: scipy
|
|
55
|
+
Requires-Dist: scikit-image
|
|
56
|
+
Requires-Dist: scikit-learn
|
|
57
|
+
Requires-Dist: torch
|
|
58
|
+
Requires-Dist: torch-cluster
|
|
59
|
+
Requires-Dist: torch-scatter
|
|
60
|
+
Provides-Extra: dev
|
|
61
|
+
Requires-Dist: black; extra == "dev"
|
|
62
|
+
Requires-Dist: coverage; extra == "dev"
|
|
63
|
+
Requires-Dist: coverage-badge; extra == "dev"
|
|
64
|
+
Requires-Dist: mypy; extra == "dev"
|
|
65
|
+
Requires-Dist: pandas-stubs; extra == "dev"
|
|
66
|
+
Requires-Dist: parameterized; extra == "dev"
|
|
67
|
+
Requires-Dist: pylint; extra == "dev"
|
|
68
|
+
Requires-Dist: pytest; extra == "dev"
|
|
69
|
+
Requires-Dist: types-Pillow; extra == "dev"
|
|
70
|
+
Provides-Extra: docs
|
|
71
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
72
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
73
|
+
Requires-Dist: sphinx-design; extra == "docs"
|
|
74
|
+
Requires-Dist: sphinx-docsearch; extra == "docs"
|
|
75
|
+
Requires-Dist: sphinxawesome-theme; extra == "docs"
|
|
76
|
+
Requires-Dist: sphinx-sitemap; extra == "docs"
|
|
77
|
+
Requires-Dist: sphinxcontrib-jsmath; extra == "docs"
|
|
78
|
+
Requires-Dist: sphinxcontrib-katex; extra == "docs"
|
|
79
|
+
Requires-Dist: sphinxcontrib-napoleon; extra == "docs"
|
|
80
|
+
Requires-Dist: sphinx_mdinclude; extra == "docs"
|
|
81
|
+
|
|
82
|
+
# PointTree
|
|
83
|
+
|
|
84
|
+
## A Python Package for Individual Tree Segmentation in 3D Point Clouds.
|
|
85
|
+
|
|
86
|
+
[](https://opensource.org/licenses/MIT)
|
|
87
|
+
[](https://github.com/ai4trees/pointtree/actions/workflows/code-quality-main.yml)
|
|
88
|
+

|
|
89
|
+
|
|
90
|
+
The package contains the official source code of the paper ["Burmeister, Josafat-Mattias, et al. "Tree Instance Segmentation in Urban 3D Point Clouds Using a Coarse-to-Fine Algorithm Based on Semantic Segmentation." ISPRS Annals of the Photogrammetry, Remote Sensing and Spatial Information Sciences 10 (2024): 79-86.](https://isprs-annals.copernicus.org/articles/X-4-W5-2024/79/2024/isprs-annals-X-4-W5-2024-79-2024.pdf)
|
|
91
|
+
|
|
92
|
+
### Package Documentation
|
|
93
|
+
|
|
94
|
+
The documentation of our package is available [here](https://ai4trees.github.io/pointtree/).
|
|
95
|
+
|
|
96
|
+
### Project Setup
|
|
97
|
+
|
|
98
|
+
The setup of our package is described in the [documentation](https://ai4trees.github.io/pointtree/#get-started).
|
|
99
|
+
|
|
100
|
+
### How to Cite
|
|
101
|
+
|
|
102
|
+
If you use our code, please consider citing our paper:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
@article{Burmeister_Tree_Instance_Segmentation_2024,
|
|
106
|
+
author = {Burmeister, Josafat-Mattias and Richter, Rico and Reder, Stefan and Mund, Jan-Peter and Döllner, Jürgen},
|
|
107
|
+
doi = {10.5194/isprs-annals-X-4-W5-2024-79-2024},
|
|
108
|
+
journal = {ISPRS Annals of the Photogrammetry, Remote Sensing and Spatial Information Sciences},
|
|
109
|
+
pages = {79--86},
|
|
110
|
+
title = {{Tree Instance Segmentation in Urban 3D Point Clouds Using a Coarse-to-Fine Algorithm Based on Semantic Segmentation}},
|
|
111
|
+
volume = {X-4/W5-2024},
|
|
112
|
+
year = {2024}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# PointTree
|
|
2
|
+
|
|
3
|
+
## A Python Package for Individual Tree Segmentation in 3D Point Clouds.
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/ai4trees/pointtree/actions/workflows/code-quality-main.yml)
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
The package contains the official source code of the paper ["Burmeister, Josafat-Mattias, et al. "Tree Instance Segmentation in Urban 3D Point Clouds Using a Coarse-to-Fine Algorithm Based on Semantic Segmentation." ISPRS Annals of the Photogrammetry, Remote Sensing and Spatial Information Sciences 10 (2024): 79-86.](https://isprs-annals.copernicus.org/articles/X-4-W5-2024/79/2024/isprs-annals-X-4-W5-2024-79-2024.pdf)
|
|
10
|
+
|
|
11
|
+
### Package Documentation
|
|
12
|
+
|
|
13
|
+
The documentation of our package is available [here](https://ai4trees.github.io/pointtree/).
|
|
14
|
+
|
|
15
|
+
### Project Setup
|
|
16
|
+
|
|
17
|
+
The setup of our package is described in the [documentation](https://ai4trees.github.io/pointtree/#get-started).
|
|
18
|
+
|
|
19
|
+
### How to Cite
|
|
20
|
+
|
|
21
|
+
If you use our code, please consider citing our paper:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
@article{Burmeister_Tree_Instance_Segmentation_2024,
|
|
25
|
+
author = {Burmeister, Josafat-Mattias and Richter, Rico and Reder, Stefan and Mund, Jan-Peter and Döllner, Jürgen},
|
|
26
|
+
doi = {10.5194/isprs-annals-X-4-W5-2024-79-2024},
|
|
27
|
+
journal = {ISPRS Annals of the Photogrammetry, Remote Sensing and Spatial Information Sciences},
|
|
28
|
+
pages = {79--86},
|
|
29
|
+
title = {{Tree Instance Segmentation in Urban 3D Point Clouds Using a Coarse-to-Fine Algorithm Based on Semantic Segmentation}},
|
|
30
|
+
volume = {X-4/W5-2024},
|
|
31
|
+
year = {2024}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pointtree"
|
|
7
|
+
version = "0.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{name = "Josafat-Mattias Burmeister", email = "burmeister@uni-potsdam.de"},
|
|
10
|
+
]
|
|
11
|
+
maintainers = [
|
|
12
|
+
{name = "Josafat-Mattias Burmeister", email = "burmeister@uni-potsdam.de"},
|
|
13
|
+
]
|
|
14
|
+
description = "A Python Package for Individual Tree Segmentation in 3D Point Clouds."
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = { file = "LICENSE" }
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Programming Language :: Python",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
29
|
+
]
|
|
30
|
+
keywords = ["tree", "point cloud", "segmentation"]
|
|
31
|
+
requires-python = ">=3.9"
|
|
32
|
+
dependencies = [
|
|
33
|
+
"numba",
|
|
34
|
+
"numba-kdtree",
|
|
35
|
+
"numpy",
|
|
36
|
+
"pandas",
|
|
37
|
+
"pyclesperanto-prototype",
|
|
38
|
+
"scipy",
|
|
39
|
+
"scikit-image",
|
|
40
|
+
"scikit-learn",
|
|
41
|
+
"torch",
|
|
42
|
+
"torch-cluster",
|
|
43
|
+
"torch-scatter"
|
|
44
|
+
]
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
dev = [
|
|
47
|
+
"black",
|
|
48
|
+
"coverage",
|
|
49
|
+
"coverage-badge",
|
|
50
|
+
"mypy",
|
|
51
|
+
"pandas-stubs",
|
|
52
|
+
"parameterized",
|
|
53
|
+
"pylint",
|
|
54
|
+
"pytest",
|
|
55
|
+
"types-Pillow",
|
|
56
|
+
]
|
|
57
|
+
docs = [
|
|
58
|
+
"sphinx",
|
|
59
|
+
"sphinx-copybutton",
|
|
60
|
+
"sphinx-design",
|
|
61
|
+
"sphinx-docsearch",
|
|
62
|
+
"sphinxawesome-theme",
|
|
63
|
+
"sphinx-sitemap",
|
|
64
|
+
"sphinxcontrib-jsmath",
|
|
65
|
+
"sphinxcontrib-katex",
|
|
66
|
+
"sphinxcontrib-napoleon",
|
|
67
|
+
"sphinx_mdinclude",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
[project.urls]
|
|
71
|
+
Homepage = "https://github.com/ai4trees/pointtree"
|
|
72
|
+
Documentation = "https://ai4trees.github.io/pointtree/"
|
|
73
|
+
Repository = "https://github.com/ai4trees/pointtree.git"
|
|
74
|
+
Issues = "https://github.com/ai4trees/pointtree/issues"
|
|
75
|
+
Changelog = "https://ai4trees.github.io/pointtree/changelog"
|
|
76
|
+
|
|
77
|
+
[tool.semantic_release]
|
|
78
|
+
version_variable = "pyproject.toml:version"
|
|
79
|
+
branch = "main"
|
|
80
|
+
changelog_file = "CHANGELOG.md"
|
|
81
|
+
build_command = "python -m build"
|
pointtree-0.0.0/setup.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
""" Utilities for configuring the package setup. """
|
|
2
|
+
|
|
3
|
+
__all__ = ["pytorch3d_is_available"]
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def pytorch3d_is_available() -> bool:
|
|
7
|
+
"""
|
|
8
|
+
Returns: `True` if PyTorch3D is installed and `False` otherwise.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
pytorch3d_available = False
|
|
12
|
+
try:
|
|
13
|
+
import pytorch3d as _ # pylint: disable=import-outside-toplevel
|
|
14
|
+
|
|
15
|
+
pytorch3d_available = True
|
|
16
|
+
except (ModuleNotFoundError, TypeError):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
return pytorch3d_available
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
""" Evaluation metrics for assesing the accuracy of tree instance segmentation algorithms. """
|
|
2
|
+
|
|
3
|
+
__all__ = ["match_instances", "instance_segmentation_metrics", "semantic_segmentation_metrics"]
|
|
4
|
+
|
|
5
|
+
from typing import Dict, List, Optional, Tuple
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pandas as pd
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def match_instances( # pylint: disable=too-many-locals
|
|
12
|
+
target: np.ndarray, prediction: np.ndarray, invalid_tree_id: int = -1, iou_treshold: float = 0.5
|
|
13
|
+
) -> Tuple[np.ndarray, np.ndarray, pd.DataFrame]:
|
|
14
|
+
r"""
|
|
15
|
+
Matches tree instances from the ground truth and the prediction based on their intersection over union (IoU).
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
target: Ground truth instance ID for each point.
|
|
19
|
+
prediction: Predicted instance ID for each point.
|
|
20
|
+
invalid_tree_id: Instance ID that is assigned to points not belonging to any tree instance. Defaults to -1.
|
|
21
|
+
iou_treshold: Minimum IoU score that a ground truth and a predicted tree instance must exceed in order to be
|
|
22
|
+
matched. The value must be greater than 0.5 in order to achieve a unique matching. Defaults to 0.5.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
Tuple of two numpy arrays and one pandas.DataFrame. The first array contains the ID of the matching target
|
|
26
|
+
instance for each predicted instance. Predicted instances that are not matched to a target instance are
|
|
27
|
+
assigned :code:`invalid_tree_id`. The second array contains the ID of the matching predicted instance for
|
|
28
|
+
each target instance. Target instances that are not matched to a predicted instance are assigned
|
|
29
|
+
:code:`invalid_tree_id`. The DataFrame contains one row per matched instance. It contains five columns
|
|
30
|
+
`"Target"`, `"Prediction"`, `"IoU"`, `"Precision"`, `"Recall"` that contain the target ID and the predicted ID
|
|
31
|
+
that match, and the IoU, precision, and recall between the two instances.
|
|
32
|
+
|
|
33
|
+
Shape:
|
|
34
|
+
- :code:`target`: :math:`(N)`
|
|
35
|
+
- :code:`prediction`: :math:`(N)`
|
|
36
|
+
- Output: The first array in the output tuple has shape :math:`(P)` and the second shape :math:`(T)`.
|
|
37
|
+
|
|
38
|
+
| where
|
|
39
|
+
|
|
|
40
|
+
| :math:`N = \text{ number of tree points}`
|
|
41
|
+
| :math:`P = \text{ number of predicted tree instances}`
|
|
42
|
+
| :math:`T = \text{ number of target tree instances}`
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
target_tree_ids = np.unique(target)
|
|
46
|
+
target_tree_ids = target_tree_ids[target_tree_ids != invalid_tree_id]
|
|
47
|
+
predicted_tree_ids = np.unique(prediction)
|
|
48
|
+
predicted_tree_ids = predicted_tree_ids[predicted_tree_ids != invalid_tree_id]
|
|
49
|
+
|
|
50
|
+
if target_tree_ids.min() != 0 or target_tree_ids.max() != len(target_tree_ids) - 1:
|
|
51
|
+
raise ValueError("The target instance IDs must be continuous, starting with zero.")
|
|
52
|
+
|
|
53
|
+
if predicted_tree_ids.min() != 0 or predicted_tree_ids.max() != len(predicted_tree_ids) - 1:
|
|
54
|
+
raise ValueError("The predicted instance IDs must be continuous, starting with zero.")
|
|
55
|
+
|
|
56
|
+
matched_target_ids = np.full(len(predicted_tree_ids), fill_value=invalid_tree_id, dtype=np.int64)
|
|
57
|
+
matched_predicted_ids = np.full(len(target_tree_ids), fill_value=invalid_tree_id, dtype=np.int64)
|
|
58
|
+
metrics = []
|
|
59
|
+
|
|
60
|
+
for target_id in target_tree_ids:
|
|
61
|
+
if target_id == invalid_tree_id:
|
|
62
|
+
continue
|
|
63
|
+
predicted_ids = prediction[np.logical_and(target == target_id, prediction != invalid_tree_id)]
|
|
64
|
+
if len(predicted_ids) == 0:
|
|
65
|
+
continue
|
|
66
|
+
values, counts = np.unique(predicted_ids, return_counts=True)
|
|
67
|
+
predicted_id = values[np.argmax(counts)]
|
|
68
|
+
intersection = np.logical_and(target == target_id, prediction == predicted_id).sum()
|
|
69
|
+
union = np.logical_or(target == target_id, prediction == predicted_id).sum()
|
|
70
|
+
iou = intersection / union
|
|
71
|
+
precision = intersection / (prediction == predicted_id).sum()
|
|
72
|
+
recall = intersection / (target == target_id).sum()
|
|
73
|
+
|
|
74
|
+
if iou > iou_treshold:
|
|
75
|
+
matched_target_ids[predicted_id] = target_id
|
|
76
|
+
matched_predicted_ids[target_id] = predicted_id
|
|
77
|
+
metrics.append(
|
|
78
|
+
{"Target": target_id, "Prediction": predicted_id, "IoU": iou, "Precision": precision, "Recall": recall}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return matched_target_ids, matched_predicted_ids, pd.DataFrame(metrics)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def instance_segmentation_metrics(
|
|
85
|
+
matched_target_ids: np.ndarray,
|
|
86
|
+
matched_predicted_ids: np.ndarray,
|
|
87
|
+
segmentation_metrics: pd.DataFrame,
|
|
88
|
+
invalid_tree_id: int = -1,
|
|
89
|
+
) -> Dict[str, float]:
|
|
90
|
+
"""
|
|
91
|
+
Calculates instance segmentation metrics.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
matched_target_ids: ID of the matching target instance for each predicted instance.
|
|
95
|
+
matched_predicted_ids: ID of the matching predicted instance for each target instance.
|
|
96
|
+
segmentation_metrics: Segmentation metrics for each pair of matched target and predicted instance.
|
|
97
|
+
invalid_tree_id: ID that is assigned to instances that could not be matched. Defaults to -1.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
A dictionary containing the following instance segmentation keys: `"tp"`, `"fp"`, `"fn"`, `"panoptic_quality"`,
|
|
101
|
+
`"detection_f1_score"`, `"detection_precision"`, `"detection_recall"`, `"segmentation_m_iou"`,
|
|
102
|
+
`"segmentation_m_precision"`, `"segmentation_m_recall"`.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
tp = (matched_target_ids != invalid_tree_id).sum()
|
|
106
|
+
|
|
107
|
+
if tp != (matched_predicted_ids != invalid_tree_id).sum():
|
|
108
|
+
raise ValueError("The number of matched instances is not the same for target and prediction.")
|
|
109
|
+
|
|
110
|
+
fp = (matched_target_ids == invalid_tree_id).sum()
|
|
111
|
+
fn = (matched_predicted_ids == invalid_tree_id).sum()
|
|
112
|
+
|
|
113
|
+
detection_precision = tp / (tp + fp)
|
|
114
|
+
detection_recall = tp / (tp + fn)
|
|
115
|
+
detection_f1_score = 2 * detection_precision * detection_recall / (detection_precision + detection_recall)
|
|
116
|
+
segmentation_m_iou = segmentation_metrics["IoU"].to_numpy().mean()
|
|
117
|
+
segmentation_m_precision = segmentation_metrics["Precision"].to_numpy().mean()
|
|
118
|
+
segmentation_m_recall = segmentation_metrics["Recall"].to_numpy().mean()
|
|
119
|
+
panoptic_quality = detection_f1_score * segmentation_m_iou
|
|
120
|
+
|
|
121
|
+
metrics = {
|
|
122
|
+
"tp": tp,
|
|
123
|
+
"fp": fp,
|
|
124
|
+
"fn": fn,
|
|
125
|
+
"panoptic_quality": panoptic_quality,
|
|
126
|
+
"detection_f1_score": detection_f1_score,
|
|
127
|
+
"detection_precision": detection_precision,
|
|
128
|
+
"detection_recall": detection_recall,
|
|
129
|
+
"segmentation_m_iou": segmentation_m_iou,
|
|
130
|
+
"segmentation_m_precision": segmentation_m_precision,
|
|
131
|
+
"segmentation_m_recall": segmentation_m_recall,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return metrics
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def semantic_segmentation_metrics( # pylint: disable=too-many-locals, too-many-statements
|
|
138
|
+
target: np.ndarray,
|
|
139
|
+
prediction: np.ndarray,
|
|
140
|
+
class_map: Dict[str, int],
|
|
141
|
+
aggregate_classes: Optional[Dict[str, List[int]]] = None,
|
|
142
|
+
) -> Dict[str, float]:
|
|
143
|
+
"""
|
|
144
|
+
Calculates semantic segmentation metrics.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
target: Ground truth semantic class IDs for each point.
|
|
148
|
+
prediction: Predicted semantic class IDs for each point.
|
|
149
|
+
class_map: A dictionary mapping class names to numeric class IDs.
|
|
150
|
+
aggregate_classes: A dictionary with which aggregations of classes can be defined. The keys are the names of the
|
|
151
|
+
aggregated classes and the values are lists of the IDs of the classes to be aggregated.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
A dictionary containing the following keys for each semantic class: `"<class_name>_iou"`,
|
|
155
|
+
`"<class_name>_precision"`, `"<class_name>_recall"`. For each aggregated class, the keys
|
|
156
|
+
`"<class_name>_iou_aggregated"`, `"<class_name>_precision_aggregated"`, `"<class_name>_recall_aggregated"` are
|
|
157
|
+
provided.
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
if len(target) != len(prediction):
|
|
161
|
+
raise ValueError("Target and prediction must have the same shape.")
|
|
162
|
+
|
|
163
|
+
aggregated_class_ids = []
|
|
164
|
+
if aggregate_classes is not None:
|
|
165
|
+
for class_ids in aggregate_classes.values():
|
|
166
|
+
aggregated_class_ids.extend(class_ids)
|
|
167
|
+
|
|
168
|
+
metrics = {}
|
|
169
|
+
|
|
170
|
+
ious = []
|
|
171
|
+
ious_aggregated = []
|
|
172
|
+
|
|
173
|
+
precisions = []
|
|
174
|
+
precisions_aggregated = []
|
|
175
|
+
|
|
176
|
+
recalls = []
|
|
177
|
+
recalls_aggregated = []
|
|
178
|
+
|
|
179
|
+
for class_name, class_id in class_map.items():
|
|
180
|
+
tp = np.logical_and(target == class_id, prediction == class_id).sum()
|
|
181
|
+
fp = np.logical_and(target != class_id, prediction == class_id).sum()
|
|
182
|
+
fn = np.logical_and(target == class_id, prediction != class_id).sum()
|
|
183
|
+
|
|
184
|
+
iou = tp / (tp + fp + fn)
|
|
185
|
+
metrics[f"{class_name}_iou"] = iou
|
|
186
|
+
ious.append(iou)
|
|
187
|
+
|
|
188
|
+
precision = tp / (tp + fp)
|
|
189
|
+
metrics[f"{class_name}_precision"] = precision
|
|
190
|
+
precisions.append(precision)
|
|
191
|
+
|
|
192
|
+
recall = tp / (tp + fn)
|
|
193
|
+
metrics[f"{class_name}_recall"] = recall
|
|
194
|
+
recalls.append(recall)
|
|
195
|
+
|
|
196
|
+
if class_id not in aggregated_class_ids:
|
|
197
|
+
ious_aggregated.append(iou)
|
|
198
|
+
precisions_aggregated.append(precision)
|
|
199
|
+
recalls_aggregated.append(recall)
|
|
200
|
+
|
|
201
|
+
metrics["m_iou"] = np.array(ious).mean()
|
|
202
|
+
metrics["m_precision"] = np.array(precisions).mean()
|
|
203
|
+
metrics["m_recall"] = np.array(recalls).mean()
|
|
204
|
+
|
|
205
|
+
if aggregate_classes is not None:
|
|
206
|
+
for class_name, aggregate_class_ids in aggregate_classes.items():
|
|
207
|
+
target_mask = np.zeros(len(target), dtype=bool)
|
|
208
|
+
prediction_mask = np.zeros(len(prediction), dtype=bool)
|
|
209
|
+
for class_id in aggregate_class_ids:
|
|
210
|
+
target_mask = np.logical_or(target_mask, target == class_id)
|
|
211
|
+
prediction_mask = np.logical_or(prediction_mask, prediction == class_id)
|
|
212
|
+
|
|
213
|
+
tp = np.logical_and(target_mask, prediction_mask).sum()
|
|
214
|
+
fp = np.logical_and(np.logical_not(target_mask), prediction_mask).sum()
|
|
215
|
+
fn = np.logical_and(target_mask, np.logical_not(prediction_mask)).sum()
|
|
216
|
+
|
|
217
|
+
iou = tp / (tp + fp + fn)
|
|
218
|
+
metrics[f"{class_name}_iou"] = iou
|
|
219
|
+
ious_aggregated.append(iou)
|
|
220
|
+
|
|
221
|
+
precision = tp / (tp + fp)
|
|
222
|
+
metrics[f"{class_name}_precision"] = precision
|
|
223
|
+
precisions_aggregated.append(precision)
|
|
224
|
+
|
|
225
|
+
recall = tp / (tp + fn)
|
|
226
|
+
metrics[f"{class_name}_recall"] = recall
|
|
227
|
+
recalls_aggregated.append(recall)
|
|
228
|
+
|
|
229
|
+
metrics["m_iou_aggregated"] = np.array(ious_aggregated).mean()
|
|
230
|
+
metrics["m_precision_aggregated"] = np.array(precisions_aggregated).mean()
|
|
231
|
+
metrics["m_recall_aggregated"] = np.array(recalls_aggregated).mean()
|
|
232
|
+
|
|
233
|
+
return metrics
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
""" A tracker that stores the execution times of different code sections. """
|
|
2
|
+
|
|
3
|
+
__all__ = ["TimeTracker"]
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TimeTracker:
|
|
9
|
+
"""A tracker that stores the execution times of different code sections."""
|
|
10
|
+
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self._time_tracking_results = {}
|
|
13
|
+
|
|
14
|
+
def reset(self):
|
|
15
|
+
"""
|
|
16
|
+
Deletes all tracked execution times.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
self._time_tracking_results = {}
|
|
20
|
+
|
|
21
|
+
def save(self, desc: str, value: float):
|
|
22
|
+
"""
|
|
23
|
+
Save the execution time of a certain code section.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
desc: Description of the tracked code. If a value has already been saved for the description, the values are
|
|
27
|
+
summed.
|
|
28
|
+
value: Execution time of the tracked code.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
if desc in self._time_tracking_results:
|
|
32
|
+
self._time_tracking_results[desc] += value
|
|
33
|
+
else:
|
|
34
|
+
self._time_tracking_results[desc] = value
|
|
35
|
+
|
|
36
|
+
def to_pandas(self) -> pd.DataFrame:
|
|
37
|
+
"""
|
|
38
|
+
Returns:
|
|
39
|
+
Tracked execution times as
|
|
40
|
+
`pandas.DataFrame <https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html>`__ with the columns
|
|
41
|
+
:code:`"Description"` and :code:`"Runtime"`.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
time_tracking_list = [[key, value] for key, value in self._time_tracking_results.items()]
|
|
45
|
+
return pd.DataFrame(time_tracking_list, columns=["Description", "Runtime"])
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
""" A context manager that tracks the execution time of the contained code. """
|
|
2
|
+
|
|
3
|
+
__all__ = ["Timer"]
|
|
4
|
+
|
|
5
|
+
from time import perf_counter
|
|
6
|
+
|
|
7
|
+
from ._time_tracker import TimeTracker
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Timer:
|
|
11
|
+
"""
|
|
12
|
+
A context manager that tracks the execution time of the contained code.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
desc: Description of the tracked code.
|
|
16
|
+
time_tracker: Time tracker in which the measured execution time is to be stored.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, desc: str, time_tracker: TimeTracker):
|
|
20
|
+
self._desc = desc
|
|
21
|
+
self._time_tracker = time_tracker
|
|
22
|
+
self._start_time = None
|
|
23
|
+
|
|
24
|
+
def __enter__(self):
|
|
25
|
+
self._start_time = perf_counter()
|
|
26
|
+
|
|
27
|
+
def __exit__(self, *_):
|
|
28
|
+
execution_time = perf_counter() - self._start_time
|
|
29
|
+
self._time_tracker.save(self._desc, execution_time)
|