Skip to content

Commit 344010e

Browse files
committed
fix: minor fixes
1 parent 06dd507 commit 344010e

File tree

3 files changed

+1
-130
lines changed

3 files changed

+1
-130
lines changed

cellseg_models_pytorch/utils/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
soft_type_flatten,
2828
type_map_flatten,
2929
)
30-
from .multiproc import run_pool
3130
from .tensor_utils import to_device, to_tensor
3231

3332
__all__ = [

cellseg_models_pytorch/utils/file_manager.py

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import scipy.io as sio
99

1010
from .mask_utils import bounding_box, get_inst_centroid, get_inst_types
11-
from .vectorize import inst2gdf, sem2gdf
1211

1312
try:
1413
import tables as tb
@@ -328,132 +327,6 @@ def gdf_to_file(
328327
elif suffix == ".geojson":
329328
gdf.to_file(path.with_suffix(".geojson"), driver="GeoJSON")
330329

331-
@staticmethod
332-
def to_gson(
333-
masks: Dict[str, np.ndarray],
334-
path: Union[str, Path],
335-
coords: Tuple[int, int, int, int] = None,
336-
compute_centroids: bool = False,
337-
compute_bboxes: bool = False,
338-
class_dict_inst: Dict[int, str] = None,
339-
class_dict_sem: Dict[int, str] = None,
340-
class_dict_cyto: Dict[int, str] = None,
341-
use_subfolders: bool = True,
342-
silence_warnings: bool = True,
343-
) -> None:
344-
"""Write a geojson/feather/parquet files from a dict of model output masks.
345-
346-
Note:
347-
Additonal computed arrays are saved if the corresponding flags are set:
348-
- centroid: The centroids of the instance masks. Shape (N, 2).
349-
- bbox: The bounding boxes of the instance masks. Shape (N, 4).
350-
351-
Note:
352-
Each specific mask type is either embedded to the end of the filename or
353-
saved to it's corresponding subfolder if `use_subfolders` is set to True:
354-
- inst: instance masks
355-
- sem: semantic masks
356-
- cyto: cytoplasm masks
357-
358-
Parameters:
359-
masks (Dict[str, np.ndarray]):
360-
The masks to be saved. E.g. {"inst": np.ndarray, "type": np.ndarray}.
361-
path (str or Path):
362-
The output filename. One of .geojson, .feather, .parquet.
363-
coords (Tuple[int, int, int, int], default=None):
364-
The XYWH-coordinates of the image patch. (x0, y0, width, height).
365-
compute_centroids (bool, default=False):
366-
Compute the centroids of the instance masks.
367-
compute_bboxes (bool, default=False):
368-
Compute the bounding boxes of the instance masks.
369-
class_dict_inst (Dict[int, str], default=None):
370-
A dictionary mapping class indices to class names.
371-
E.g. {1: 'neoplastic', 2: 'immune'}.
372-
class_dict_sem (Dict[int, str], default=None):
373-
A dictionary mapping class indices to class names.
374-
E.g. {1: 'tumor', 2: 'stroma'}.
375-
class_dict_cyto (Dict[int, str], default=None):
376-
A dictionary mapping class indices to class names.
377-
E.g. {1: 'neoplastic_cyto', 2: 'connective_cyto'}.
378-
use_subfolders (bool, default=True):
379-
If True, saves the masks to their respective subfolders. I.e. subfolders
380-
called 'inst', 'sem', 'cyto'. If False, the mask type is embedded in the
381-
end of the filename.
382-
silence_warnings (bool, default=True):
383-
If True, warnings are silenced.
384-
"""
385-
path = Path(path)
386-
387-
xoff = coords[0] if coords is not None else None
388-
yoff = coords[1] if coords is not None else None
389-
390-
if masks.get("inst", None) is not None:
391-
if use_subfolders:
392-
inst_subdir = path.parent / "inst"
393-
inst_subdir.mkdir(parents=True, exist_ok=True)
394-
inst_path = inst_subdir / path.name
395-
else:
396-
inst_path = path.parent / f"{path.stem}_inst{path.suffix}"
397-
398-
if masks.get("type", None) is not None:
399-
inst_gdf = inst2gdf(
400-
masks["inst"],
401-
masks["type"],
402-
xoff=xoff,
403-
yoff=yoff,
404-
class_dict=class_dict_inst,
405-
)
406-
else:
407-
inst_gdf = inst2gdf(masks["inst"], xoff=xoff, yoff=yoff)
408-
409-
if compute_centroids:
410-
inst_gdf["centroid"] = inst_gdf["geometry"].centroid
411-
if compute_bboxes:
412-
inst_gdf["bbox"] = inst_gdf["geometry"].apply(lambda x: x.bounds)
413-
414-
FileHandler.gdf_to_file(inst_gdf, inst_path, silence_warnings)
415-
416-
if masks.get("sem", None) is not None:
417-
if use_subfolders:
418-
sem_subdir = path.parent / "sem"
419-
sem_subdir.mkdir(parents=True, exist_ok=True)
420-
sem_path = sem_subdir / path.name
421-
else:
422-
sem_path = path.parent / f"{path.stem}_sem{path.suffix}"
423-
424-
sem_gdf = sem2gdf(
425-
masks["sem"],
426-
xoff=xoff,
427-
yoff=yoff,
428-
class_dict=class_dict_sem,
429-
)
430-
FileHandler.gdf_to_file(sem_gdf, sem_path, silence_warnings)
431-
432-
if masks.get("cyto", None) is not None:
433-
if use_subfolders:
434-
cyto_subdir = path.parent / "cyto"
435-
cyto_subdir.mkdir(parents=True, exist_ok=True)
436-
cyto_path = cyto_subdir / path.name
437-
else:
438-
cyto_path = path.parent / f"{path.stem}_cyto{path.suffix}"
439-
440-
if masks.get("cyto_type", None) is not None:
441-
cyto_gdf = inst2gdf(
442-
masks["cyto"],
443-
masks["cyto_type"],
444-
xoff=xoff,
445-
yoff=yoff,
446-
class_dict=class_dict_cyto,
447-
)
448-
else:
449-
cyto_gdf = inst2gdf(
450-
masks["cyto"],
451-
xoff=xoff,
452-
yoff=yoff,
453-
class_dict=class_dict_cyto,
454-
)
455-
FileHandler.gdf_to_file(cyto_gdf, cyto_path, silence_warnings)
456-
457330
@staticmethod
458331
def to_mat(
459332
masks: Dict[str, np.ndarray],

cellseg_models_pytorch/utils/mask_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ def binarize(inst_map: np.ndarray) -> np.ndarray:
173173
np.ndarray:
174174
Binary mask. Shape (H, W). Type: uint8.
175175
"""
176-
binary = np.copy(inst_map > 0)
177-
return binary.astype("uint8")
176+
return (inst_map > 0).astype("uint8")
178177

179178

180179
# ported from https://github.com/vqdang/hover_net/blob/master/src/loader/augs.py

0 commit comments

Comments
 (0)