Skip to content
Snippets Groups Projects
Commit 83dc4a79 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Now just running into broadcast errors, presumably on patch mask boundaries

parent b312c89c
No related branches found
No related tags found
2 merge requests!18Completed (de)serialization of RoiSet,!16Completed (de)serialization of RoiSet
......@@ -223,13 +223,19 @@ class RoiSet(object):
acc_raw: GenericImageDataAccessor,
df: pd.DataFrame,
patch_masks: dict, # dict of ndarray, where key is integer label
params: RoiSetMetaParams = RoiSetMetaParams(),
):
assert len(df) == len(patch_masks)
se_patch_masks = pd.Series(patch_masks)
# df_merged = pd.merge(df, se_patch_masks)
assert all(patch_masks.keys())
assert df.apply(lambda x: x, axis=1)
assert False
zmask = np.zeros((*acc_raw.hw, 1, acc_raw.nz), dtype=bool)
def _label_obj(r):
sl = np.s_[r.ebb_y0:r.ebb_y1, r.ebb_x0:r.ebb_x1, :, r.zi:r.zi + 1]
zmask[sl] = patch_masks[r.label]
df.apply(lambda x: _label_obj(x), axis=1)
obj_ids = _get_label_ids(zmask, allow_3d=True, connect_3d=False)
return RoiSet(acc_raw, obj_ids, params)
@staticmethod
def filter_df(df: pd.DataFrame, filters: RoiFilter = None) -> pd.DataFrame:
......
......@@ -3,6 +3,8 @@ import unittest
import numpy as np
from pathlib import Path
import pandas as pd
from model_server.conf.testing import output_path, roiset_test_data
from model_server.base.roiset import RoiSetExportParams, RoiSetMetaParams
......@@ -303,3 +305,36 @@ class TestRoiSetFromZmask(unittest.TestCase):
)
self.assertEqual(roiset.count, id_map.data.max())
self.assertGreater(len(roiset.get_df()['zi'].unique()), 1)
return roiset
def test_create_roiset_from_df_and_patch_masks(self):
ref_roiset = self.test_create_roiset_from_2d_obj_ids()
res = ref_roiset.run_exports(
output_path / 'roiset_from_3d',
roiset_test_data['pipeline_params']['segmentation_channel'],
'ref',
params=RoiSetExportParams(patch_masks={'pad_to': 256}, dataframe=True)
)
where_df = output_path / 'roiset_from_3d' / 'dataframe' / 'ref.csv'
self.assertTrue(where_df.exists())
df_test = pd.read_csv(where_df)
# zmask = np.zeros((*self.stack.hw, 1, self.stack.nz), dtype=bool)
print('hi')
fn = output_path / 'roiset_from_3d' / 'patch_masks' / 'ref-la{:04d}-zi{:04d}.png'
patch_masks = {}
def _label_obj(r):
sl = np.s_[r.ebb_y0:r.ebb_y1, r.ebb_x0:r.ebb_x1, :, r.zi:r.zi + 1]
self.assertEqual(str(sl), r.slice)
patch_masks[r.label] = generate_file_accessor(str(fn).format(r.label, r.zi)).data
# zmask[sl] = True
df_test.apply(lambda x: _label_obj(x), axis=1)
roiset_test = RoiSet.from_df_and_patch_masks(self.stack, df_test, patch_masks)
print('')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment