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
+ 6
4
Compare changes
  • Side-by-side
  • Inline
@@ -174,7 +174,7 @@ def _make_df_from_object_ids(acc_raw, acc_obj_ids, expand_box_by) -> pd.DataFram
# TODO: make this contingent on whether seg is included
def _make_binary_mask(r):
acc = InMemoryDataAccessor(acc_obj_ids.data == r.label)
cropped = acc.get_mono(0, mip=True).crop_hw((r.y0, r.x0, (r.y1 - r.y0), (r.x1 - r.x0))).data
cropped = acc.get_mono(0, mip=True).crop_hw((r.y0, r.x0, (r.y1 - r.y0), (r.x1 - r.x0))).data[:, :, 0, 0]
return cropped
df['binary_mask'] = df.apply(
@@ -251,7 +251,8 @@ def _make_object_ids_from_df(df: pd.DataFrame, sd: dict) -> InMemoryDataAccessor
def _label_obj(r):
sl = np.s_[r.y0:r.y1, r.x0:r.x1, :, r.zi:r.zi + 1]
id_mask[sl] = id_mask[sl] + r.label * r.binary_mask
mask = np.expand_dims(r.binary_mask, (2, 3))
id_mask[sl] = id_mask[sl] + r.label * mask
df.apply(_label_obj, axis=1)
return InMemoryDataAccessor(id_mask)
@@ -523,10 +524,11 @@ class RoiSet(object):
patch = np.zeros((roi.ebb_h, roi.ebb_w, 1, 1), dtype='uint8')
patch[roi.relative_slice][:, :, 0, 0] = roi.binary_mask * 255
else:
# TODO: shape issues here
patch = (roi.binary_mask * 255).astype('uint8')
if pad_to:
patch = pad(patch, pad_to)
return patch
return np.expand_dims(patch, (2, 3))
dfe = self._df.copy()
dfe['patch_mask'] = dfe.apply(_make_patch_mask, axis=1)
@@ -787,7 +789,7 @@ class RoiSet(object):
try:
ma_acc = generate_file_accessor(where / 'tight_patch_masks' / fname)
assert ma_acc.chroma == 1 and ma_acc.nz == 1
mask_data = ma_acc.data / np.iinfo(ma_acc.data.dtype).max
mask_data = ma_acc.data[:, :, 0, 0] / np.iinfo(ma_acc.data.dtype).max
return mask_data
except Exception as e:
raise DeserializeRoiSet(e)
Loading