Skip to content

Commit 3e96c6f

Browse files
authored
Fix Semantic segmentation averaging by too many classes (#326)
* Fix Semantic segmentation averaging by too many classes * Fix FWAVACC * Set actual version
1 parent 97cb618 commit 3e96c6f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.14.5](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.5) - 2022-07-05
9+
10+
### Fixed
11+
- Averaging of rich semantic segmentation taxonomies not taking into account missing classes
12+
13+
## [0.14.4](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.4) - 2022-06-21
14+
15+
### Fixed
16+
- Regression that caused Validate filter statements to not work
17+
818
## [0.14.3](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.3) - 2022-06-21
919

1020
### Fixed

nucleus/metrics/segmentation_metrics.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ def _calculate_confusion_matrix(
185185
) = convert_to_instance_seg_confusion(
186186
confusion, annotation, prediction
187187
)
188+
else:
189+
ann_labels = list(
190+
dict.fromkeys(s.label for s in annotation.annotations)
191+
)
192+
pred_labels = list(
193+
dict.fromkeys(s.label for s in prediction.annotations)
194+
)
195+
missing_or_filtered_labels = set(ann_labels) - set(pred_labels)
196+
non_taxonomy_classes = {
197+
segment.index
198+
for segment in annotation.annotations
199+
if segment.label in missing_or_filtered_labels
200+
}
188201

189202
return confusion, non_taxonomy_classes
190203

@@ -644,9 +657,13 @@ def _metric_impl(
644657
+ confusion.sum(axis=0)
645658
- np.diag(confusion)
646659
)
647-
freq = confusion.sum(axis=0) / confusion.sum()
648-
fwavacc = (freq[freq > 0] * iu[freq > 0]).sum()
649-
fwavacc.put(list(non_taxonomy_classes), np.nan)
660+
predicted_counts = confusion.sum(axis=0).astype(np.float_)
661+
predicted_counts.put(list(non_taxonomy_classes), np.nan)
662+
freq = predicted_counts / np.nansum(predicted_counts)
663+
iu.put(list(non_taxonomy_classes), np.nan)
664+
fwavacc = (
665+
np.nan_to_num(freq[freq > 0]) * np.nan_to_num(iu[freq > 0])
666+
).sum()
650667
mean_fwavacc = np.nanmean(fwavacc)
651668
return ScalarResult(value=np.nan_to_num(mean_fwavacc), weight=confusion.sum()) # type: ignore
652669

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = "scale-nucleus"
24-
version = "0.14.3"
24+
version = "0.14.5"
2525
description = "The official Python client library for Nucleus, the Data Platform for AI"
2626
license = "MIT"
2727
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

0 commit comments

Comments
 (0)