Skip to content

Commit 9204604

Browse files
committed
🐛 Fix saving annotation properties
1 parent 91d134d commit 9204604

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

tests/engines/test_semantic_segmentor.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import sqlite3
56
from pathlib import Path
67

78
import numpy as np
@@ -89,7 +90,8 @@ def test_semantic_segmentor_patches(
8990

9091
def test_save_annotation_store(
9192
sample_patch1: Path, sample_patch2: Path, tmp_path: Path
92-
):
93+
) -> None:
94+
"""Test for saving output as annotation store."""
9395
segmentor = SemanticSegmentor(
9496
model="fcn-tissue_mask", batch_size=32, verbose=False, device=device
9597
)
@@ -106,17 +108,19 @@ def test_save_annotation_store(
106108
output_type="annotationstore",
107109
)
108110

109-
assert output == tmp_path / "output1" / "output.zarr"
111+
assert output == tmp_path / "output1" / "output.db"
112+
con = sqlite3.connect(output)
113+
cur = con.cursor()
114+
annotations_properties = list(cur.execute("SELECT properties FROM annotations"))
110115

111-
output = zarr.open(output, mode="r")
112-
assert 0.24 < np.mean(output["predictions"][:]) < 0.25
113-
assert "probabilities" not in output.keys() # noqa: SIM118
116+
assert annotations_properties is not None
114117

115118

116119
def test_hovernet_dat() -> None:
120+
"""Test for comparing annotation store saving."""
117121
from pathlib import Path
118122

119123
from tiatoolbox.utils.misc import store_from_dat
120124

121125
path_to_file = Path.cwd().parent.parent / "output" / "0.dat"
122-
out = store_from_dat(path_to_file, scale_factor=(1.0, 1.0))
126+
_ = store_from_dat(path_to_file, scale_factor=(1.0, 1.0))

tiatoolbox/utils/misc.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,8 @@ def dict_to_store_semantic_segmentor(
12651265
count = 1
12661266
store = SQLiteStore()
12671267

1268+
_ = class_dict # use it once overlay is working
1269+
12681270
annotations = []
12691271

12701272
for type_class in layer_list:
@@ -1290,14 +1292,16 @@ def dict_to_store_semantic_segmentor(
12901292
"coordinates": scaled_coords,
12911293
},
12921294
)
1293-
annotations.append(
1294-
Annotation(
1295-
geometry=make_valid_poly(
1296-
feature_geom,
1297-
origin=origin,
1298-
),
1299-
properties={"type": "mask"},
1300-
)
1295+
annotations.extend(
1296+
[
1297+
Annotation(
1298+
geometry=make_valid_poly(
1299+
feature_geom,
1300+
origin=origin,
1301+
),
1302+
properties={"type": "mask"},
1303+
)
1304+
]
13011305
)
13021306

13031307
_ = store.append_many(annotations, [str(i) for i in range(len(annotations))])

0 commit comments

Comments
 (0)