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

Moved patch stack-specific ilastik model

parent 008c2bd2
No related branches found
No related tags found
No related merge requests found
......@@ -6,47 +6,11 @@ import numpy as np
import pandas as pd
import skimage
import uuid
import vigra
from extensions.chaeo.accessors import MonoPatchStack, MonoPatchStackFromFile
from extensions.ilastik.models import IlastikObjectClassifierFromSegmentationModel
from model_server.accessors import generate_file_accessor, GenericImageDataAccessor, InMemoryDataAccessor, write_accessor_data_to_file
from extensions.chaeo.accessors import MonoPatchStackFromFile
from extensions.chaeo.models import PatchStackObjectClassifier
from model_server.accessors import generate_file_accessor, GenericImageDataAccessor, write_accessor_data_to_file
class PatchStackObjectClassifier(IlastikObjectClassifierFromSegmentationModel):
"""
Wrap ilastik object classification for inputs comprising raw image and binary segmentation masks, both represented
as time-series images where each frame contains only one object.
"""
def infer(self, input_acc: MonoPatchStack, segmentation_acc: MonoPatchStack) -> (np.ndarray, dict):
assert segmentation_acc.is_mask()
assert input_acc.chroma == 1
tagged_input_data = vigra.taggedView(input_acc.make_tczyx(), 'tczyx')
tagged_seg_data = vigra.taggedView(segmentation_acc.make_tczyx(), 'tczyx')
dsi = [
{
'Raw Data': self.PreloadedArrayDatasetInfo(preloaded_array=tagged_input_data),
'Segmentation Image': self.PreloadedArrayDatasetInfo(preloaded_array=tagged_seg_data),
}
]
obmaps = self.shell.workflow.batchProcessingApplet.run_export(dsi, export_to_array=True) # [z x h x w x n]
assert len(obmaps) == 1, 'ilastik generated more than one object map'
# for some reason ilastik scrambles these axes to Z(1)YX(1)
assert obmaps[0].shape == (input_acc.nz, 1, input_acc.hw[0], input_acc.hw[1], 1)
yxcz = np.moveaxis(
obmaps[0][:, :, :, :, 0],
[2, 3, 1, 0],
[0, 1, 2, 3]
)
assert yxcz.shape == input_acc.shape
return InMemoryDataAccessor(data=yxcz), {'success': True}
def get_dataset_info(h5: h5py.File, lane : int = 0):
"""
......
import numpy as np
import vigra
from extensions.chaeo.accessors import MonoPatchStack
from extensions.ilastik.models import IlastikObjectClassifierFromSegmentationModel
from model_server.accessors import InMemoryDataAccessor
class PatchStackObjectClassifier(IlastikObjectClassifierFromSegmentationModel):
"""
Wrap ilastik object classification for inputs comprising raw image and binary segmentation masks, both represented
as time-series images where each frame contains only one object.
"""
def infer(self, input_acc: MonoPatchStack, segmentation_acc: MonoPatchStack) -> (np.ndarray, dict):
assert segmentation_acc.is_mask()
assert input_acc.chroma == 1
tagged_input_data = vigra.taggedView(input_acc.make_tczyx(), 'tczyx')
tagged_seg_data = vigra.taggedView(segmentation_acc.make_tczyx(), 'tczyx')
dsi = [
{
'Raw Data': self.PreloadedArrayDatasetInfo(preloaded_array=tagged_input_data),
'Segmentation Image': self.PreloadedArrayDatasetInfo(preloaded_array=tagged_seg_data),
}
]
obmaps = self.shell.workflow.batchProcessingApplet.run_export(dsi, export_to_array=True) # [z x h x w x n]
assert len(obmaps) == 1, 'ilastik generated more than one object map'
# for some reason ilastik scrambles these axes to Z(1)YX(1)
assert obmaps[0].shape == (input_acc.nz, 1, input_acc.hw[0], input_acc.hw[1], 1)
yxcz = np.moveaxis(
obmaps[0][:, :, :, :, 0],
[2, 3, 1, 0],
[0, 1, 2, 3]
)
assert yxcz.shape == input_acc.shape
return InMemoryDataAccessor(data=yxcz), {'success': True}
\ 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