Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
instance_segmentation_classic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maciej Wielgosz
instance_segmentation_classic
Commits
a9c4b746
Commit
a9c4b746
authored
2 years ago
by
Maciej Wielgosz
Browse files
Options
Downloads
Patches
Plain Diff
update metrics - inst global to account for broken plots in phils code
parent
a9bec7c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helpers/remove_points_of_class_from_pc.py
+84
-0
84 additions, 0 deletions
helpers/remove_points_of_class_from_pc.py
metrics/instance_segmentation_metrics_in_folder.py
+9
-1
9 additions, 1 deletion
metrics/instance_segmentation_metrics_in_folder.py
with
93 additions
and
1 deletion
helpers/remove_points_of_class_from_pc.py
0 → 100644
+
84
−
0
View file @
a9c4b746
import
argparse
import
glob
import
os
import
laspy
import
numpy
as
np
class
RemovePointsOfClassFromPC
:
def
__init__
(
self
,
folder_name
,
class_name
,
class_value
,
verbose
=
False
):
self
.
folder_name
=
folder_name
self
.
class_name
=
class_name
self
.
class_value
=
class_value
self
.
verbose
=
verbose
def
get_paths_of_files
(
self
,
folder_name
):
# use glob to get all the paths of the files in the folder
paths
=
glob
.
glob
(
os
.
path
.
join
(
folder_name
,
"
*.las
"
),
recursive
=
False
)
# check if the folder is empty
if
len
(
paths
)
==
0
:
raise
Exception
(
"
The folder is empty
"
)
if
self
.
verbose
:
print
(
"
The number of files in the folder {} is {}
"
.
format
(
folder_name
,
len
(
paths
)))
return
paths
def
read_one_las_file_and_remove_points
(
self
,
file_path
,
class_name
,
class_value
):
# read the las file
las_file
=
laspy
.
read
(
file_path
)
# check if at least one point has the class value in the las file
if
np
.
sum
(
las_file
[
class_name
]
==
class_value
)
==
0
:
if
self
.
verbose
:
print
(
"
No points with the class value {} in the file {}
"
.
format
(
class_value
,
file_path
))
print
(
"
No points removed from the file {}
"
.
format
(
file_path
))
# create a new las file with the same header as the original las file
new_file
=
laspy
.
create
(
point_format
=
las_file
.
header
.
point_format
,
file_version
=
las_file
.
header
.
version
)
# write the points to the las file except the points of the class
new_file
.
points
=
las_file
.
points
[
las_file
[
class_name
]
!=
class_value
]
# write the las file
new_file
.
write
(
file_path
)
def
remove_points_of_class_from_pc
(
self
,
folder_name
,
class_name
,
class_value
):
# get the paths of all the files in the folder
paths
=
self
.
get_paths_of_files
(
folder_name
)
# read all the files and remove the points of the class
for
path
in
paths
:
if
self
.
verbose
:
print
(
"
Removing points from the file {}
"
.
format
(
path
))
self
.
read_one_las_file_and_remove_points
(
path
,
class_name
,
class_value
)
if
self
.
verbose
:
print
(
"
Done
"
)
def
__call__
(
self
):
self
.
remove_points_of_class_from_pc
(
self
.
folder_name
,
self
.
class_name
,
self
.
class_value
)
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Remove points of a class from a point cloud
"
)
parser
.
add_argument
(
"
-f
"
,
"
--folder_name
"
,
type
=
str
,
help
=
"
The folder name where the point clouds are stored
"
)
parser
.
add_argument
(
"
-n
"
,
"
--class_name
"
,
type
=
str
,
help
=
"
The class name of the points to be removed
"
)
parser
.
add_argument
(
"
-c
"
,
"
--class_value
"
,
type
=
int
,
help
=
"
The class value of the points to be removed
"
)
parser
.
add_argument
(
"
-v
"
,
"
--verbose
"
,
action
=
"
store_true
"
,
help
=
"
Print the progress
"
)
args
=
parser
.
parse_args
()
# get the arguments
folder_name
=
args
.
folder_name
class_name
=
args
.
class_name
class_value
=
args
.
class_value
verbose
=
args
.
verbose
# remove the points of the class from the point cloud
remove_points_of_class_from_pc
=
RemovePointsOfClassFromPC
(
folder_name
,
class_name
,
class_value
,
verbose
)
remove_points_of_class_from_pc
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
metrics/instance_segmentation_metrics_in_folder.py
+
9
−
1
View file @
a9c4b746
...
@@ -111,7 +111,15 @@ class InstanceSegmentationMetricsInFolder():
...
@@ -111,7 +111,15 @@ class InstanceSegmentationMetricsInFolder():
# f1_scores_weighted_list.append(f1_score_weighted)
# f1_scores_weighted_list.append(f1_score_weighted)
# calculate the mean f1 score of weighted f1 scores
# calculate the mean f1 score of weighted f1 scores
mean_f1_score
=
sum
(
f1_scores_weighted_list
)
/
len
(
f1_scores_weighted_list
)
# mean_f1_score = sum(f1_scores_weighted_list) / len(f1_scores_weighted_list)
# use a dirty hack to compute the mean of the metrics (accounts for broken point clouds caused by phils code)
mean_f1_score
=
sum
(
f1_scores_weighted_list
)
/
len
(
gt_las_file_paths
)
print
(
'
numer of files:
'
+
str
(
len
(
gt_las_file_paths
)))
# calculate the mean metrics for all the elements in the metric_dict_list
# calculate the mean metrics for all the elements in the metric_dict_list
# create a mean_metrics dictionary and initialize it with zeros
# create a mean_metrics dictionary and initialize it with zeros
mean_metrics
=
{}
mean_metrics
=
{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment