Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions LICENSE

This file was deleted.

50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Still in development

# cellmap-flow

```bash
$ cellmap_flow_server

Usage: cellmap_flow_server [OPTIONS] COMMAND [ARGS]...

Examples:
To use Dacapo run the following commands:
cellmap_flow_server dacapo -r my_run -i iteration -d data_path

To use custom script
cellmap_flow_server script -s script_path -d data_path

To use bioimage-io model
cellmap_flow_server bioimage -m model_path -d data_path


Commands:
bioimage Run the CellMapFlow server with a bioimage-io model.
dacapo Run the CellMapFlow server with a DaCapo model.
script Run the CellMapFlow server with a custom script.
```


Currently available:
## Using custom script:
which enable using any model by providing a script e.g. [example/model_spec.py](example/model_spec.py)
e.g.
```bash
cellmap_flow script -c /groups/cellmap/cellmap/zouinkhim/cellmap-flow/example/model_spec.py -d /nrs/cellmap/data/jrc_mus-cerebellum-1/jrc_mus-cerebellum-1.zarr/recon-1/em/fibsem-uint8/s0
```

## Using Dacapo model:
which enable inference using a Dacapo model by providing the run name and iteration number
e.g.
```bash
cellmap_flow dacapo -r 20241204_finetune_mito_affs_task_datasplit_v3_u21_kidney_mito_default_cache_8_1 -i 700000 -d /nrs/cellmap/data/jrc_ut21-1413-003/jrc_ut21-1413-003.zarr/recon-1/em/fibsem-uint8/s0"
```

## Using bioimage-io model:
still in development


## Limitation:
Currently only supporting data locating in /nrs/cellmap or /groups/cellmap because there is a data server already implemented for them.


2 changes: 2 additions & 0 deletions cellmap_flow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = "0.1.0"
__version_info__ = tuple(int(i) for i in __version__.split("."))
69 changes: 69 additions & 0 deletions cellmap_flow/bioimagezoo_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# %%
from bioimageio.core import load_description
from bioimageio.core import predict # , predict_many

# %%
from bioimageio.core import Tensor
import numpy as np
from bioimageio.core import Sample
from bioimageio.core.digest_spec import get_member_ids


# create random input tensor
def process_chunk(model, idi, roi):
input_image = idi.to_ndarray_ts(roi)
# add dimensions to start of input image
# print(input_image.shape)
# input_image = block_reduce(input_image, (4,1,1), np.mean, cval=0)
# print(input_image.shape)
# input_image = (input_image - np.min(input_image))/np.max(input_image)
# input_image = np.random.rand(1, 1, 64, 64, 64).astype(np.float32)
if len(model.outputs[0].axes) == 5:
input_image = input_image[np.newaxis, np.newaxis, ...].astype(np.float32)
test_input_tensor = Tensor.from_numpy(
input_image, dims=["batch", "c", "z", "y", "x"]
)
else:
input_image = input_image[:, np.newaxis, ...].astype(np.float32)

test_input_tensor = Tensor.from_numpy(
input_image, dims=["batch", "c", "y", "x"]
)
sample_input_id = get_member_ids(model.inputs)[0]
sample_output_id = get_member_ids(model.outputs)[0]

sample = Sample(
members={sample_input_id: test_input_tensor}, stat={}, id="sample-from-numpy"
)
prediction: Sample = predict(
model=model, inputs=sample, skip_preprocessing=sample.stat is not None
)
ndim = prediction.members[sample_output_id].data.ndim
output = prediction.members[sample_output_id].data.to_numpy()
if ndim < 5 and len(model.outputs) > 1:
if len(model.outputs) > 1:
outputs = []
for id in get_member_ids(model.outputs):
output = prediction.members[id].data.to_numpy()
if output.ndim == 3:
output = output[:, np.newaxis, ...]
outputs.append(output)
output = np.concatenate(outputs, axis=1)
output = np.ascontiguousarray(np.swapaxes(output, 1, 0))

else:
output = output[0, ...]
# if ndim == 5:
# # then is b,c,z,y,x, and only want z,y,x
# output = 255 * output[0, ...]
# elif ndim == 4:
# # then is b,c,y,x since it is 2d which is really z,c,y,x
# output = 255 * output[0, 0, ...]
output = 255 * output
output = output.astype(np.uint8)
return output


# %%
# import torch
# from pydeepimagej.yaml_utils import create_model_yaml
Loading