Skip to content

Commit 4f67ddd

Browse files
Merge pull request #181 from bioimage-io/stuff
Small post-release clean up
2 parents cae7e87 + 41f0d8b commit 4f67ddd

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# core-bioimage-io-python
22

3-
Python specific core utilities for running models in the [BioImage Model Zoo](https://bioimage.io)
3+
Python specific core utilities for running models in the [BioImage Model Zoo](https://bioimage.io).
44

55
## Installation
66

77
### Via Conda
88

9-
The `bioimageio.core` package supports various back-ends for running BioimageIO networks:
9+
The `bioimageio.core` package can be installed from conda-forge via
10+
```
11+
conda install -c conda-forge bioimageio.core
12+
```
13+
if you don't install any additional deep learning libraries, you will only be able to use general convenience functionality, but not any functionality for model prediction.
14+
To install additional deep learning libraries use:
1015

1116
* Pytorch/Torchscript:
1217
```bash
@@ -69,6 +74,13 @@ Run prediction for an image stored on disc:
6974
bioimageio predict-image -m <MODEL> -i <INPUT> -o <OUTPUT>
7075
```
7176

77+
Run prediction for multiple images stored on disc:
78+
```
79+
bioimagei predict-images -m <MODEL> -i <INPUT_PATTERN> - o <OUTPUT_FOLDER>
80+
```
81+
`<INPUT_PATTERN>` is a `glob` pattern to select the desired images, e.g. `/path/to/my/images/*.tif`.
82+
83+
7284
## From python
7385

7486
`bioimageio.core` can be used as a python library. See the notebook [example/bioimageio-core-usage.ipynb](https://github.com/bioimage-io/core-bioimage-io-python/blob/main/example/bioimageio-core-usage.ipynb) for usage examples.

bioimageio/core/weight_converter/keras/tensorflow.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
# adapted from
1515
# https://github.com/deepimagej/pydeepimagej/blob/master/pydeepimagej/yaml/create_config.py#L236
16-
def _convert_tf1(keras_weight_path, output_path, zip_weights):
16+
def _convert_tf1(keras_weight_path, output_path, input_name, output_name, zip_weights):
1717
def build_tf_model():
1818
keras_model = keras.models.load_model(keras_weight_path)
1919

2020
builder = saved_model.builder.SavedModelBuilder(output_path)
2121
signature = saved_model.signature_def_utils.predict_signature_def(
22-
inputs={"input": keras_model.input}, outputs={"output": keras_model.output}
22+
inputs={input_name: keras_model.input}, outputs={output_name: keras_model.output}
2323
)
2424

2525
signature_def_map = {saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature}
@@ -98,6 +98,10 @@ def convert_weights_to_tensorflow_saved_model_bundle(
9898
raise RuntimeError(f"Tensorflow major versions of model {model_tf_major_ver} is not {tf_major_ver}")
9999

100100
if tf_major_ver == 1:
101-
return _convert_tf1(weight_path, str(path_), zip_weights)
101+
if len(model.inputs) != 1 or len(model.outputs) != 1:
102+
raise NotImplementedError(
103+
"Weight conversion for models with multiple inputs or outputs is not yet implemented."
104+
)
105+
return _convert_tf1(weight_path, str(path_), model.inputs[0].name, model.outputs[0].name, zip_weights)
102106
else:
103-
raise NotImplementedError
107+
raise NotImplementedError("Weight conversion for tensorflow 2 is not yet implemented.")

tests/build_spec/test_build_spec.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import bioimageio.spec as spec
23
from bioimageio.core import load_raw_resource_description, load_resource_description
34
from bioimageio.core.resource_io import nodes
@@ -14,6 +15,7 @@ def _test_build_spec(
1415
use_implicit_output_shape=False,
1516
add_deepimagej_config=False,
1617
use_original_covers=False,
18+
use_absoloute_arch_path=False,
1719
):
1820
from bioimageio.core.build_spec import build_model
1921

@@ -28,6 +30,11 @@ def _test_build_spec(
2830
weight_spec = model_spec.weights["pytorch_state_dict"]
2931
model_kwargs = None if weight_spec.kwargs is missing else weight_spec.kwargs
3032
architecture = str(weight_spec.architecture)
33+
if use_absoloute_arch_path:
34+
arch_path, cls_name = architecture.split(":")
35+
arch_path = os.path.abspath(os.path.join(root, arch_path))
36+
assert os.path.exists(arch_path)
37+
architecture = f"{arch_path}:{cls_name}"
3138
weight_type_ = None # the weight type can be auto-detected
3239
elif weight_type == "torchscript":
3340
architecture = None
@@ -152,3 +159,10 @@ def test_build_spec_deepimagej_keras(unet2d_keras, tmp_path):
152159
# test with original covers
153160
def test_build_spec_with_original_covers(unet2d_nuclei_broad_model, tmp_path):
154161
_test_build_spec(unet2d_nuclei_broad_model, tmp_path / "model.zip", "torchscript", use_original_covers=True)
162+
163+
164+
# test with absolute path for the architecture file
165+
def test_build_spec_abs_arch_path(unet2d_nuclei_broad_model, tmp_path):
166+
_test_build_spec(
167+
unet2d_nuclei_broad_model, tmp_path / "model.zip", "pytorch_state_dict", use_absoloute_arch_path=True
168+
)

0 commit comments

Comments
 (0)