Skip to content

Commit 0528942

Browse files
committed
✅ Add functionality patch mode annotations
1 parent e6dc905 commit 0528942

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tiatoolbox/models/engine/nucleus_instance_segmentor.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from typing_extensions import Unpack
2222

2323
from tiatoolbox import DuplicateFilter, logger
24+
from tiatoolbox.annotation import SQLiteStore
2425
from tiatoolbox.annotation.storage import Annotation
2526
from tiatoolbox.models.engine.semantic_segmentor import (
2627
SemanticSegmentor,
@@ -675,15 +676,19 @@ def save_predictions(
675676
output_path = save_path.parent / (str(i) + ".db")
676677

677678
origin = predictions_.pop("coordinates")[:2]
678-
679-
out_file = dict_to_store(
679+
store = SQLiteStore()
680+
store = dict_to_store(
681+
store=store,
680682
processed_predictions=predictions_,
681683
class_dict=class_dict,
682684
scale_factor=scale_factor,
683685
origin=origin,
684686
)
685687

686-
save_paths.append(out_file)
688+
store.commit()
689+
store.dump(output_path)
690+
691+
save_paths.append(output_path)
687692

688693
if return_probabilities:
689694
msg = (
@@ -1132,11 +1137,12 @@ def run(
11321137

11331138

11341139
def dict_to_store(
1140+
store: SQLiteStore,
11351141
processed_predictions: dict,
11361142
class_dict: dict | None = None,
11371143
origin: tuple[float, float] = (0, 0),
11381144
scale_factor: tuple[float, float] = (1, 1),
1139-
) -> list[Annotation]:
1145+
) -> AnnotationStore:
11401146
"""Helper function to convert dict to store."""
11411147
contour = processed_predictions.pop("contour")
11421148

@@ -1147,20 +1153,25 @@ def dict_to_store(
11471153
feature2geometry(
11481154
{
11491155
"type": processed_predictions.get("geom_type", "Polygon"),
1150-
"coordinates": scale_factor * np.array(contour_),
1156+
"coordinates": scale_factor * np.array([contour_]),
11511157
},
11521158
),
1153-
origin,
1159+
tuple(origin),
11541160
),
11551161
{
11561162
prop: (
1157-
class_dict[processed_predictions[prop]][i]
1163+
class_dict[processed_predictions[prop][i]]
11581164
if prop == "type" and class_dict is not None
1159-
else processed_predictions[prop]
1165+
# Intention is convert arrays to list
1166+
# There might be int or float values which need to be
1167+
# converted to arrays first and then apply tolist().
1168+
else np.array(processed_predictions[prop][i]).tolist()
11601169
)
11611170
for prop in processed_predictions
11621171
},
11631172
)
11641173
ann.append(ann_)
1174+
logger.info("Added %d annotations.", len(ann))
1175+
store.append_many(ann)
11651176

1166-
return ann
1177+
return store

0 commit comments

Comments
 (0)