Skip to content
Snippets Groups Projects

RoiSet facilitates object detection models

Merged Christopher Randolph Rhodes requested to merge dev_obj_det into staging
1 file
+ 10
11
Compare changes
  • Side-by-side
  • Inline
+ 10
11
@@ -331,7 +331,6 @@ def safe_add(a, g, b):
).astype(a.dtype)
def make_object_ids_from_df(df: pd.DataFrame, sd: dict) -> InMemoryDataAccessor:
# TODO: generate rectangular masks if running without segmentation
id_mask = np.zeros((sd['Y'], sd['X'], 1, sd['Z']), dtype='uint16')
if 'binary_mask' not in df.columns:
raise MissingSegmentationError('RoiSet dataframe does not contain segmentation')
@@ -665,14 +664,6 @@ class RoiSet(object):
return InMemoryDataAccessor(om)
def export_dataframe(self, csv_path: Path) -> str:
# TODO: move this inside of .serialize()
csv_path.parent.mkdir(parents=True, exist_ok=True)
# TODO: suppress errors or check if binary_mask doesn't exist
self._df.drop(['expanded_slice', 'slice', 'relative_slice', 'binary_mask'], axis=1).to_csv(csv_path, index=False)
return csv_path.name
def export_patch_masks(self, where: Path, pad_to: int = None, prefix='mask', expanded=False) -> pd.DataFrame:
patches_df = self.get_patch_masks(pad_to=pad_to, expanded=expanded).copy()
@@ -947,12 +938,20 @@ class RoiSet(object):
pad_to=None,
expanded=False
)
# record patch masks paths to dataframe, then save static columns to CSV
se_pa = df_exp.patch_mask_path.apply(
lambda x: str(Path('tight_patch_masks') / x)
).rename('tight_patch_masks_path')
self._df = self._df.join(se_pa)
df_fn = self.export_dataframe(where / 'dataframe' / (prefix + '.csv'))
record['dataframe'] = str(Path('dataframe') / df_fn)
csv_path = where / 'dataframe' / (prefix + '.csv')
csv_path.parent.mkdir(parents=True, exist_ok=True)
self._df.drop(
['expanded_slice', 'slice', 'relative_slice', 'binary_mask'],
axis=1
).to_csv(csv_path, index=False)
record['dataframe'] = str(Path('dataframe') / csv_path.name)
record['tight_patch_masks'] = list(se_pa)
return record
Loading