Skip to content

Commit 816a568

Browse files
committed
🚧 Update script for annotation store
1 parent cf5b50e commit 816a568

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

tests/engines/test_semantic_segmentor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def test_semantic_segmentor_patches(
8787
assert "probabilities" not in output.keys() # noqa: SIM118
8888

8989

90-
# def test_hovernet_dat() -> None:
91-
# from tiatoolbox.utils.misc import store_from_dat
92-
# from pathlib import Path
93-
# path_to_file = Path.cwd().parent.parent / "output" / "0.dat"
94-
# out = store_from_dat(path_to_file, scale_factor=(1.0, 1.0))
90+
def test_hovernet_dat() -> None:
91+
from tiatoolbox.utils.misc import store_from_dat
92+
from pathlib import Path
93+
path_to_file = Path.cwd().parent.parent / "output" / "0.dat"
94+
out = store_from_dat(path_to_file, scale_factor=(1.0, 1.0))

tiatoolbox/utils/misc.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,9 @@ def dict_to_store_semantic_segmentor(
12621262
layer_list = np.delete(layer_list, np.where(layer_list == 0))
12631263
layer_info_dict = {}
12641264
count = 1
1265+
store = SQLiteStore()
1266+
1267+
annotations = []
12651268

12661269
for type_class in layer_list:
12671270
layer = np.where(preds == type_class, 1, 0).astype("uint8")
@@ -1278,6 +1281,23 @@ def dict_to_store_semantic_segmentor(
12781281
}
12791282
count += 1
12801283

1284+
origin = (0, 0)
1285+
1286+
annotations.append(
1287+
Annotation(
1288+
geometry=make_valid_poly(
1289+
feature2geometry(
1290+
{
1291+
"type": "Polygon",
1292+
"coordinates": scale_factor * coords,
1293+
},
1294+
),
1295+
origin=origin,
1296+
),
1297+
properties={},
1298+
)
1299+
)
1300+
12811301
# return layer_info_dict
12821302

12831303
# if "coordinates" not in patch_output:
@@ -1323,19 +1343,18 @@ def dict_to_store_semantic_segmentor(
13231343
# )
13241344
#
13251345
# store = SQLiteStore()
1326-
# _ = store.append_many(annotations, [str(i) for i in range(len(annotations))])
1327-
#
1346+
_ = store.append_many(annotations, [str(i) for i in range(len(annotations))])
1347+
13281348
# # if a save director is provided, then dump store into a file
1329-
# if save_path:
1330-
# # ensure parent directory exists
1331-
# save_path.parent.absolute().mkdir(parents=True, exist_ok=True)
1332-
# # ensure proper db extension
1333-
# save_path = save_path.parent.absolute() / (save_path.stem + ".db")
1334-
# store.dump(save_path)
1335-
# return save_path
1336-
#
1337-
# return store
1349+
if save_path:
1350+
# ensure parent directory exists
1351+
save_path.parent.absolute().mkdir(parents=True, exist_ok=True)
1352+
# ensure proper db extension
1353+
save_path = save_path.parent.absolute() / (save_path.stem + ".db")
1354+
store.dump(save_path)
1355+
return save_path
13381356

1357+
return store
13391358

13401359

13411360
def get_zarr_array(zarr_array: zarr.core.Array | np.ndarray | list) -> np.ndarray:

0 commit comments

Comments
 (0)