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

Start end-to-end transfer method to ilastik object model

parent 9e018533
No related branches found
No related tags found
No related merge requests found
......@@ -13,3 +13,5 @@ if __name__ == '__main__':
where_output=autonumber_new_directory(root, 'labeled_patches'),
)
print('Finished')
......@@ -4,8 +4,22 @@ import h5py
import ilastik.applets.objectClassification
import numpy as np
import pandas as pd
import tifffile
from extensions.ilastik.models import IlastikObjectClassifierModel
from model_server.accessors import generate_file_accessor
def get_dataset_info(h5):
lane = 'Input Data/infos/lane0000'
info = {}
for gk in ['Raw Data', 'Segmentation Image']:
info[gk] = {}
for dk in ['location', 'filePath', 'shape']:
try:
info[gk][dk] = h5[f'{lane}/{gk}/{dk}'][()]
except Exception as e:
print(e)
return info
def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta):
......@@ -22,6 +36,9 @@ def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta):
hf.write(f'{line[0]} --- {line[1]}\n')
h5.visititems(lambda k, v: print(k + ' : ' + str(v)))
# put certain h5 groups in scope
h5info = get_dataset_info(h5)
# change key of label names
ln = ['none'] + list(df_stack_meta.sort_values('annotation_class_id').annotation_class.unique())
del h5['ObjectClassification/LabelNames']
......@@ -39,9 +56,44 @@ def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta):
ds[1] = float(df_stack_meta.loc[df_stack_meta.zi == idx, 'annotation_class_id'].iat[0])
print(f'Changed label {ti} from {la_old} to {ds[1]}')
def generate_ilastik_object_classifier(template_ilp, where_training: str):
# validate input data
where = Path(where_training)
zstacks = {
'raw': {
'path': where / 'zstack_train_raw.tif',
},
'seg': {
'path': where / 'zstack_train_mask.tif',
}
}
for k, v in zstacks.items():
# assert v['path'].exists(), 'Could not find input z-stack: ' + v['path']
# ff = tifffile.imread(v['path'])
# v['nz'] = ff.shape[0]
# v['hw'] = ff.shape[1:2]
# v['dtype'] = ff.dtype
v['acc'] = generate_file_accessor(v['path'])
assert zstacks['raw']['acc'].is_binary()
assert zstacks['raw']
with h5py.File(template_ilp, 'r+') as h5:
pass
if __name__ == '__main__':
ilp = 'c:/Users/rhodes/model-server/ilastik/test_autolabel_obj.ilp'
ilp = 'c:/Users/rhodes/model-server/ilastik/test_autolabel_obj - Copy.ilp'
# ilp = 'c:/Users/rhodes/model-server/ilastik/test_template_obj.ilp'
df = pd.read_csv(
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output/labeled_patches-20231014-0002/train_stack.csv'
)
transfer_labels_to_ilastik_ilp(ilp, df)
\ No newline at end of file
# transfer_labels_to_ilastik_ilp(ilp, df)
generate_ilastik_object_classifier(
ilp,
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output/labeled_patches-20231014-0002'
)
\ No newline at end of file
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