Closed constantinpape closed 2 years ago
2d-unet: bioimageio validate
fails with:
{'outputs': {0: {'postprocessing': {0: {'_schema': ['Invalid `kwargs` for '
"'scale_range': "
"{'reference_tensor': "
"['Missing data for "
"required field.']}"]}}}}}
So it looks like the reference_tensor
is missing for the scale_range
postprocessing; but I am not quite sure, cc @FynnBe.
3d-unet: bioimageio validate
fails with
{'documentation': ['Invalid suffix '
'(https:/github.com/HenriquesLab/ZeroCostDL4Mic/wiki): '
'Replacement index 0 out of range for positional args tuple',
'Invalid as_posix '
'(https:/github.com/HenriquesLab/ZeroCostDL4Mic/wiki): '
'expected local, relative file path.'],
'inputs': {0: {'data_range': ['Not a valid tuple.'],
'preprocessing': {0: {'name': ['Missing data for required '
'field.'],
'scale_range': ['Unknown field.']}}}},
'language': ['Must be one of: python, java.'],
'outputs': {0: {'data_range': ['Not a valid tuple.'],
'postprocessing': {0: {'binarize': ['Unknown field.'],
'name': ['Missing data for required '
'field.']}}}},
'packaged_by': {0: {'_schema': ['Invalid input type.']}},
'type': ['Missing data for required field.'],
'weights': defaultdict(<class 'dict'>,
{'keras_hdf5': {'value': [{'authors': {0: {'_schema': ['Invalid '
'input '
'type.']}},
'weights_format': ['Must be '
'equal '
'to '
'pytorch_state_dict.']},
{'authors': {0: {'_schema': ['Invalid '
'input '
'type.']}},
'weights_format': ['Must be '
'equal '
'to '
'pytorch_script.']},
{'authors': {0: {'_schema': ['Invalid '
'input '
'type.']}}},
{'authors': {0: {'_schema': ['Invalid '
'input '
'type.']}},
'weights_format': ['Must be '
'equal '
'to '
'tensorflow_js.']},
{'authors': {0: {'_schema': ['Invalid '
'input '
'type.']}},
'weights_format': ['Must be '
'equal '
'to '
'tensorflow_saved_model_bundle.']},
{'authors': {0: {'_schema': ['Invalid '
'input '
'type.']}},
'weights_format': ['Must be '
'equal '
'to '
'onnx.']}]}})}
@esgomezm I can load the 2d model now.
It does not work in ilastik yet, but that's because neither keras nor tensorflow are working in our current release yet. I will discuss with @FynnBe and @k-dominik how we best add and (back) and test support for them.
This is good news! If you need to create any additional file to set up a python environment, just let me know
@esgomezm we are making some progress with the python model runner, but now I am running into issues when trying to load the zero-cost models. tf.keras.models.load_model
fails with this stack trace:
invalid local relative path: auto_converted_documentation.md
invalid local relative path: auto_converted_documentation.md
Traceback (most recent call last):
File "check_model.py", line 13, in <module>
pp = create_prediction_pipeline(bioimageio_model=bio_model,
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_prediction_pipeline.py", line 187, in create_prediction_pipeline
model_adapter: ModelAdapter = create_model_adapter(
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_model_adapter.py", line 59, in create_model_adapter
return adapter_cls(bioimageio_model=bioimageio_model, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 39, in __init__
super().__init__(bioimageio_model=bioimageio_model, weight_format=weight_format, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 23, in __init__
self.model = tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 211, in load_model
loader_impl.parse_saved_model(filepath)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/saved_model/loader_impl.py", line 111, in parse_saved_model
raise IOError("SavedModel file does not exist at: %s/{%s|%s}" %
OSError: SavedModel file does not exist at: /tmp/bioimageio_cache/2d-unet---zerocostdl4mic_tensorflow_saved_model_bundle_unzipped/2du-net_zerocostdl4mic_tf_model.zip/{saved_model.pbtxt|saved_model.pb}
Any ideas?
Hi!
I know, I think. Your model is zipped as defined in the bioimage specs. You need to unzip first to find the saved_model.pb.
In these cases, it might be easier for you to load the Keras model (.h5).
Here is the code I used to export the models, in case it helps:
I know, I think. Your model is zipped as defined in the bioimage specs. You need to unzip first to find the saved_model.pb.
Ok, I will try to unzip and see what happens.
In these cases, it might be easier for you to load the Keras model (.h5).
The Keras model fails with a different error:
Traceback (most recent call last):
File "check_model.py", line 13, in <module>
pp = create_prediction_pipeline(bioimageio_model=bio_model,
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_prediction_pipeline.py", line 187, in create_prediction_pipeline
model_adapter: ModelAdapter = create_model_adapter(
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_model_adapter.py", line 59, in create_model_adapter
return adapter_cls(bioimageio_model=bioimageio_model, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 46, in __init__
super().__init__(bioimageio_model=bioimageio_model, weight_format=weight_format, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 24, in __init__
self.model = tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 206, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 199, in load_model_from_hdf5
model.compile(**saving_utils.compile_args_from_training_config(
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/saving_utils.py", line 218, in compile_args_from_training_config
loss = _deserialize_nested_config(losses.deserialize, loss_config)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/saving_utils.py", line 259, in _deserialize_nested_config
return deserialize_fn(config)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/losses.py", line 1854, in deserialize
return deserialize_keras_object(
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 377, in deserialize_keras_object
raise ValueError(
ValueError: Unknown loss function: _weighted_binary_crossentropy
@esgomezm with unzipped weigths I get the following error when trying to load into tf:
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 35, in __init__
self.model = tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 212, in load_model
return saved_model_load.load(filepath, compile, options)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 130, in load
_read_legacy_metadata(object_graph_def, metadata)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 179, in _read_legacy_metadata
node_paths = _generate_object_paths(object_graph_def)
File "/home/pape/Work/software/conda/miniconda3/envs/torch-em-test/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 204, in _generate_object_paths
for reference in object_graph_def.nodes[current_node].children:
IndexError: list index (0) out of range
Ok, I guess the problem is that I am using tensorflow 2:
python -c "import tensorflow; print(tensorflow.__version__)"
2.4.1
Which version should I use for these models?
Which version should I use for these models?
the 2D unet has tensorflow_version: 1.15 set (the 3d one does not specify)
makes me think we should make those fields mandatory and also add a mandatory pytorch_version for the pytorch weights...
All the models are TF 1.15 as we cannot load TF 2 in ImageJ.
makes me think we should make those fields mandatory and also add a mandatory pytorch_version for the pytorch weights...
Yes, for Python environments at least seems unavoidable
@esgomezm tensorflow 1.15 is pretty annoying as dependency, as it does not exist for most python versions, see https://stackoverflow.com/questions/61491893/i-cannot-install-tensorflow-version-1-15-through-pip.
Do you think it would also work with 14?
Edit: also looks like conda does not have 1.15 at all: https://anaconda.org/conda-forge/tensorflow/files
@constantinpape does TF 1.15.2 work? It should work with tf 1.14 but it seems weird because we take the latest 1.x version and it's always 1.1.5:
%tensorflow_version 1.x
It should work with tf 1.14 but it seems weird because we take the latest 1.x version and it's always 1.1.5:
It seems like 1.15 was not properly released, at least it's not really available via conda or pip.
It seems like 1.15 was not properly released, at least it's not really available via conda or pip. No idea. In the tensorflow saved_model field we specify
tensorflow_version: 1.15.2
, but for the keras weights would it be important both, keras and tf?
I have updated the 3D UNet model.yaml and rdf
Ok, I have set up an environment with 1.14 now, but this yields a different set of errors:
Keras Model:
Traceback (most recent call last):
File "check_model.py", line 15, in <module>
devices=["cpu"])
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_prediction_pipeline.py", line 189, in create_prediction_pipeline
bioimageio_model=bioimageio_model, devices=devices, weight_format=weight_format
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_model_adapter.py", line 59, in create_model_adapter
return adapter_cls(bioimageio_model=bioimageio_model, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 59, in __init__
super().__init__(bioimageio_model=bioimageio_model, weight_format=weight_format, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 37, in __init__
self.model = tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 143, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 160, in load_model_from_hdf5
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'
tensorflow model:
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_prediction_pipeline.py", line 189, in create_prediction_pipeline
bioimageio_model=bioimageio_model, devices=devices, weight_format=weight_format
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_model_adapter.py", line 59, in create_model_adapter
return adapter_cls(bioimageio_model=bioimageio_model, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 53, in __init__
super().__init__(bioimageio_model=bioimageio_model, weight_format=weight_format, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 37, in __init__
self.model = tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 150, in load_model
'Unable to load model. Filepath is not an hdf5 file (or h5py is not '
OSError: Unable to load model. Filepath is not an hdf5 file (or h5py is not available) or SavedModel.
@esgomezm do you have a requirements.txt
or environment.yaml
file that sets up a valid env for these models?
It's a problem with the Keras version and TF 1. Try h5py==2.10
, this one should solve it.
Sorry, I don't have the requirements list as everything is written down in the notebooks: https://github.com/HenriquesLab/ZeroCostDL4Mic/tree/master/Colab_notebooks/BioImage.io%20notebooks
Also, keras backend was imported from tensorflow rather than importing keras directly.
I updated the h5py version, now I get the following error for the keras model:
Traceback (most recent call last):
File "check_model.py", line 15, in <module>
devices=["cpu"])
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_prediction_pipeline.py", line 189, in create_prediction_pipeline
bioimageio_model=bioimageio_model, devices=devices, weight_format=weight_format
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_model_adapter.py", line 59, in create_model_adapter
return adapter_cls(bioimageio_model=bioimageio_model, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 59, in __init__
super().__init__(bioimageio_model=bioimageio_model, weight_format=weight_format, devices=devices)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 37, in __init__
self.model = tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 143, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 178, in load_model_from_hdf5
training_config, custom_objects))
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 336, in compile
self.loss, self.output_names)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_utils.py", line 1349, in prepare_loss_functions
loss_functions = [get_loss_function(loss) for _ in output_names]
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_utils.py", line 1349, in <listcomp>
loss_functions = [get_loss_function(loss) for _ in output_names]
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_utils.py", line 1085, in get_loss_function
loss_fn = losses.get(loss)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/losses.py", line 1166, in get
return deserialize(identifier)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/losses.py", line 1157, in deserialize
printable_module_name='loss function')
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/generic_utils.py", line 210, in deserialize_keras_object
raise ValueError('Unknown ' + printable_module_name + ':' + object_name)
ValueError: Unknown loss function:_weighted_binary_crossentropy
tensorflow model still has the same error as before
@esgomezm we have the same issues for the frunet model (https://raw.githubusercontent.com/deepimagej/models/master/fru-net_sev_segmentation/model.yaml). Do you have an environment file for that one? Without a reproducible env where we know that the models should run debugging this is pretty hopeless. (This also means that we need an env export for zerocost, otherwise the models will not be portable).
Keras: my fault. I need to save the model without compiling it. Otherwise it complains about the custom loss function.
For the tensorflow model, I manage to load it and run a prediction with the following code in a clean colab session using tensorflow==1.15.2
:
!pip install h5py==2.10
%tensorflow_version 1.x
import tensorflow as tf
import numpy as np
input_key = 'input' # name from the model.yaml
output_key = 'output' # name from the model.yaml
tag = tf.saved_model.tag_constants.SERVING # it's usually this one but otherwise it's given in config/deepimagej field in model.yaml.
graph2 = tf.Graph()
with graph2.as_default():
with tf.Session(graph=graph2) as sess:
# Restore saved values
print('\nRestoring...')
tf.saved_model.loader.load(
sess,
[tag],
"/content/tensorflow_saved_model_bundle"
)
# Get model input and output tensor names in the graph
x_tensor_name = signature[signature_key].inputs[input_key].name
y_tensor_name = signature[signature_key].outputs[output_key].name
# Get restored model input and output
input_tensor = graph2.get_tensor_by_name(x_tensor_name) # name of the input tensor in the model.yaml
output_tensor = graph2.get_tensor_by_name(y_tensor_name) # name of the input tensor in the model.yaml
# Random input dataset
input_data = np.random.rand(1, 256, 256, 8, 1)
input_data[:,150:200, 150:200] = 1
# Run prediction
output_array = sess.run(output_tensor, {input_tensor:input_data})
The error you got is weird because it's looking for a keras model rather than the protobuffer (self.model = tf.keras.models.load_model(weight_file)
)
For the FRU-Net it's also given in the notebook or the documentation (but you can avoid all except tensorflow):
SimpleITK==1.1
tensorflow-gpu==1.13.1
keras==1.2.2
skimage
scikit-image
Pillow==4.3.0
I hope this helps
@esgomezm Ok, I understand the issue now: In tf1 we can't use the keras API to load (and predict with) the model saved as model bundle. (This is possible in tf2 and the preferred way when you read the doc). With the code snippet you posted above it should work, but the definitions of signature
and signature_key
are missing in
x_tensor_name = signature[signature_key].inputs[input_key].name y_tensor_name = signature[signature_key].outputs[output_key].name
Can you please update the code so that it's correct?
Please, check this one:
!pip install h5py==2.10
%tensorflow_version 1.x
import tensorflow as tf
import numpy as np
input_key = 'input' # name from the model.yaml
output_key = 'output' # name from the model.yaml
export_path = "/content/tensorflow_saved_model_bundle"
tag = tf.saved_model.tag_constants.SERVING # it's usually this one but otherwise it's given in config/deepimagej field in model.yaml.
signature_key = tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY # it's usually this one but otherwise it's given in config/deepimagej field in model.yaml.
graph = tf.Graph()
with graph.as_default():
with tf.Session() as sess:
# load the model
meta_graph_def = tf.saved_model.loader.load(
sess,
[tag],
export_path,
)
# Get the input-output dictionary
signature = meta_graph_def.signature_def
# Get model input and output tensor names in the graph
x_tensor_name = signature[signature_key].inputs[input_key].name
y_tensor_name = signature[signature_key].outputs[output_key].name
# Get restored model input and output
input_tensor = graph.get_tensor_by_name(x_tensor_name) # name of the input tensor in the model.yaml
output_tensor = graph.get_tensor_by_name(y_tensor_name) # name of the input tensor in the model.yaml
# Random input dataset
input_data = np.random.rand(1, 256, 256, 8, 1)
input_data[:,150:200, 150:200] = 1
# Run prediction
output_array = sess.run(output_tensor, {input_tensor:input_data})
Thanks, @esgomezm. I think everything is set up to work in principle now, however there are several issues with the models (both zerocost models and the models we use for testing):
ValueError: Cannot feed value of shape (1, 2048, 2048, 1) for Tensor 'input_1:0', which has shape '(?, 400, 400, 1)'
. I guess that model only works for a fixed shape?! But then the test tensors need to be of exactly that size!E ValueError: ('Unrecognized keyword arguments:', dict_keys(['input_dtype']))
, see full stack-trace below. Maybe that's because the keras model is not compiled correctly?TypeError: Unexpected keyword argument passed to optimizer: learning_rate
. Maybe again some issue with compilation? See full stack trace below.Frunet keras backtrace:
bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py:25: in _load_model
return tf.keras.models.load_model(weight_file)
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/saving.py:234: in load_mode
l
model = model_from_config(model_config, custom_objects=custom_objects)
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/saving.py:324: in model_fro
m_config
return deserialize(config, custom_objects=custom_objects)
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/layers/serialization.py:74: in des
erialize
printable_module_name='layer')
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py:192: in des
erialize_keras_object
list(custom_objects.items())))
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py:1263: in from_co
nfig
process_layer(layer_data)
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py:1249: in process
_layer
layer = deserialize_layer(layer_data, custom_objects=custom_objects)
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/layers/serialization.py:74: in des
erialize
printable_module_name='layer')
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py:194: in des
erialize_keras_object
return cls.from_config(cls_config)
../../software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py:402: in from_
config
return cls(**config)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <tensorflow.python.keras.engine.input_layer.InputLayer object at 0x7f16c55e7c10>, input_shape = [400, 400, 1], batch_size = None
dtype = None, input_tensor = None, sparse = False, name = 'input_1', kwargs = {'input_dtype': 'float32'}
batch_input_shape = [None, 400, 400, 1]
def __init__(self,
input_shape=None,
batch_size=None,
dtype=None,
input_tensor=None,
sparse=False,
name=None,
**kwargs):
if 'batch_input_shape' in kwargs:
batch_input_shape = kwargs.pop('batch_input_shape')
if input_shape and batch_input_shape:
raise ValueError('Only provide the input_shape OR '
'batch_input_shape argument to '
'InputLayer, not both at the same time.')
batch_size = batch_input_shape[0]
input_shape = batch_input_shape[1:]
if kwargs:
> raise ValueError('Unrecognized keyword arguments:', kwargs.keys())
E ValueError: ('Unrecognized keyword arguments:', dict_keys(['input_dtype']))
zerocost-keras:
self.model = self._load_model(weight_file)
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_tensorflow_model_adapter.py", line 25, in _load_model
return tf.keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/engine/saving.py", line 249, in load_model
optimizer_config, custom_objects=custom_objects)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/optimizers.py", line 838, in deserialize
printable_module_name='optimizer')
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 194, in deserialize_keras_object
return cls.from_config(cls_config)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/optimizers.py", line 159, in from_config
return cls(**config)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/optimizers.py", line 471, in __init__
super(Adam, self).__init__(**kwargs)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/tensorflow/python/keras/optimizers.py", line 68, in __init__
'passed to optimizer: ' + str(k))
TypeError: Unexpected keyword argument passed to optimizer: learning_rate
It's nice to hear that some are working :)
- frunet-tf: Fails with ValueError: Cannot feed value of shape (1, 2048, 2048, 1) for Tensor 'input_1:0', which has shape '(?, 400, 400, 1)'. I guess that model only works for a fixed shape?! But then the test tensors need to be of exactly that size!
Yes, this model has a fixed shape, but I didn't know that the test tensor should be of that exact shape. If there's some halo, you may need to do tiling anyways.
- frunet-keras: Fails with E ValueError: ('Unrecognized keyword arguments:', dict_keys(['input_dtype'])), see full stack-trace below. Maybe that's because the keras model is not compiled correctly?
Loading it using keras worked for me, so the problem is due to the dependencies most probably. I let you some code:
pip install tensorflow-gpu==1.13.1
pip install keras==1.2.2
from keras.models import load_model
model = load_model('fully_residual_dropout_segmentation.h5')
The zerocost notebooks have all, except StarDist, the same problem I guess. I'll update all of them tomorrow and upload again. In case you want to test with the numpy arrays meantime, here you can find the data for the 3DUNet and 2D UNet
Yes, this model has a fixed shape, but I didn't know that the test tensor should be of that exact shape. If there's some halo, you may need to do tiling anyways.
It would be better to avoid tiling for the test, because that adds more complexity (because there can be different tiling strategies). I don't think the halo would mean we need to do tiling in that case.
Thanks for the keras code and updating the zero cost models, I will give it another try tomorrow.
pip install keras==1.2.2
This keras version is so old that it does not work with python 3.7+ on conda. Is there any chance to use a 2.X version?
Ok, I can run the keras model now (but it fails with the usual size error); I am not sure if we can set up a reproducible environment for this though...
@esgomezm I created a version of the zero-cost 3d unet trained on arabidopsis (https://bioimage.io/#/?id=10.5072%2Fzenodo.849110) now that partially works. I have uploaded it here: https://oc.embl.de/index.php/apps/files/?dir=/&fileid=11351577
The current state is: tensorflow prediction works, keras fails with:
File "/home/pape/Work/bioimageio/python-bioimage-io/bioimageio/core/prediction_pipeline/_model_adapters/_keras_model_adapter.py", line 22, in __init__
self.model = keras.models.load_model(weight_file)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/models.py", line 142, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/models.py", line 193, in model_from_config
return layer_from_config(config, custom_objects=custom_objects)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/utils/layer_utils.py", line 40, in layer_from_config
custom_objects=custom_objects)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/engine/topology.py", line 2582, in from_config
process_layer(layer_data)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/engine/topology.py", line 2560, in process_layer
custom_objects=custom_objects)
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/utils/layer_utils.py", line 42, in layer_from_config
return layer_class.from_config(config['config'])
File "/home/pape/Work/software/conda/miniconda3/envs/bio-core-dev/lib/python3.7/site-packages/keras/engine/topology.py", line 1025, in from_config
return cls(**config)
TypeError: __init__() got an unexpected keyword argument 'dtype'
I assume that this is again some issue with the keras version or how the model was compiled.
Anyway, I think that the prediction part of the python library works, now we need to fix the models and then make a new ilastik release that supports this. Most of the ilastik team will be gone for the rest of August. You can set up a development environment with the python library, if you want to work on this in the meantime: https://github.com/bioimage-io/python-bioimage-io#set-up-development-environment https://github.com/bioimage-io/python-bioimage-io#command-line
Hi @constantinpape!
I'm playing with the python code. I got the following issue with the last version of the repository when I try to set up the development environment
(pip install -e . --no-deps
). It seems to be from the way the version number is recovered:
/home/esgomezm/.local/lib/python3.7/site-packages/secretstorage/dhcrypto.py:16: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
from cryptography.utils import int_from_bytes
/home/esgomezm/.local/lib/python3.7/site-packages/secretstorage/util.py:25: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
from cryptography.utils import int_from_bytes
Obtaining file:///home/esgomezm/Documents/DEEPIMAGEJ/python-bioimage-io
Installing build dependencies ... done
Getting requirements to build wheel ... error
ERROR: Command errored out with exit status 1:
command: /home/esgomezm/anaconda3/envs/bio-core-dev/bin/python3.7 /home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpyekzpa4p
cwd: /home/esgomezm/Documents/DEEPIMAGEJ/python-bioimage-io
Complete output (24 lines):
Traceback (most recent call last):
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>
main()
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 117, in get_requires_for_build_wheel
return hook(config_settings)
File "/tmp/pip-build-env-kpk7wcxs/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 155, in get_requires_for_build_wheel
config_settings, requirements=['wheel'])
File "/tmp/pip-build-env-kpk7wcxs/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 135, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-kpk7wcxs/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 259, in run_setup
self).run_setup(setup_script=setup_script)
File "/tmp/pip-build-env-kpk7wcxs/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 150, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 10, in <module>
VERSION = json.loads(VERSION_FILE.read_text())["version"]
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/pathlib.py", line 1221, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/pathlib.py", line 1208, in open
opener=self._opener)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/pathlib.py", line 1063, in _opener
return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/home/esgomezm/Documents/DEEPIMAGEJ/python-bioimage-io/bioimageio/spec/VERSION'
----------------------------------------
WARNING: Discarding file:///home/esgomezm/Documents/DEEPIMAGEJ/python-bioimage-io. Command errored out with exit status 1: /home/esgomezm/anaconda3/envs/bio-core-dev/bin/python3.7 /home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpyekzpa4p Check the logs for full command output.
ERROR: Command errored out with exit status 1: /home/esgomezm/anaconda3/envs/bio-core-dev/bin/python3.7 /home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpyekzpa4p Check the logs for full command output.
When trying to install tensorflow bioimageio.core back-end, I get the following message:
$ conda install -c conda-forge -c ilastik-forge bioimageio.core tensorflow
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- bioimageio.core
Current channels:
- https://conda.anaconda.org/conda-forge/linux-64
- https://conda.anaconda.org/conda-forge/noarch
- https://conda.anaconda.org/ilastik-forge/linux-64
- https://conda.anaconda.org/ilastik-forge/noarch
- https://repo.anaconda.com/pkgs/main/linux-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/linux-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
I tried to test 3D UNet model for Arabidopsis dataset, using the development environment and I get the following message which I'm not sure whether it refers to errors in the model.yaml or the way I'm trying to test it:
$ bioimageio-test -m /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/model.yaml
Traceback (most recent call last):
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/fields.py", line 434, in _deserialize
return raw_nodes.URI(uri_string=value)
File "<string>", line 8, in __init__
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/base_nodes.py", line 101, in __post_init__
raise ValueError("Invalid URI or relative path. (use URI with scheme 'file' for absolute file paths)")
ValueError: Invalid URI or relative path. (use URI with scheme 'file' for absolute file paths)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/esgomezm/anaconda3/envs/bio-core-dev/bin/bioimageio-test", line 33, in <module>
sys.exit(load_entry_point('bioimageio.core', 'console_scripts', 'bioimageio-test')())
File "/home/esgomezm/Documents/DEEPIMAGEJ/python-bioimage-io/bioimageio/core/model_test.py", line 72, in main
model_test(args.model, args.weight_format, args.devices, args.decimals)
File "/home/esgomezm/Documents/DEEPIMAGEJ/python-bioimage-io/bioimageio/core/model_test.py", line 31, in model_test
model = load_resource_description(source)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/delegator.py", line 113, in load_resource_description
raw_rd, _ = ensure_raw_resource_description(source, root_path, update_to_current_format)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/delegator.py", line 91, in ensure_raw_resource_description
return io_cls.ensure_raw_rd(raw_rd, root_path)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/io_.py", line 260, in ensure_raw_rd
local_raw_rd = resolve_uri(raw_rd, root_path)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/functools.py", line 840, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/utils.py", line 246, in _resolve_uri_str
return resolve_uri(fields.URI().deserialize(uri), root_path)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/marshmallow/fields.py", line 364, in deserialize
output = self._deserialize(value, attr, data, **kwargs)
File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/fields.py", line 436, in _deserialize
raise ValidationError(value) from e
marshmallow.exceptions.ValidationError: /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/model.yaml
I'm playing with the python code. I got the following issue with the last version of the repository when I try to set up the development environment (
pip install -e . --no-deps
). It seems to be from the way the version number is recovered:
I see, this is a recent issue that is fixed already, but not yet merged on master. Can you try with the branch python-bioimageio
branch predict
?
When trying to install tensorflow bioimageio.core back-end, I get the following message:
Yes, bioimageio.core
(which is the package corresponding to the python-bioimageio
repo) is not on conda yet, only bioimageio.spec
is. We will add bioimageio.core
to conda once we have made sure that prediction works also for tf and keras models.
$ bioimageio-test -m /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/model.yaml Traceback (most recent call last): File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/fields.py", line 434, in _deserialize return raw_nodes.URI(uri_string=value) File "
", line 8, in init File "/home/esgomezm/anaconda3/envs/bio-core-dev/lib/python3.7/site-packages/bioimageio/spec/shared/base_nodes.py", line 101, in __post_init__ raise ValueError("Invalid URI or relative path. (use URI with scheme 'file' for absolute file paths)") ValueError: Invalid URI or relative path. (use URI with scheme 'file' for absolute file paths)
Yes, that issue is known, see #228. We will fix it. In the meantime you can circumvent it by passing a relative path instead of an absolute path to the model.
@esgomezm I ran the validation for the tf zero cost model now and it still fails:
marshmallow.exceptions.ValidationError: {'language': ['Must be one of: python, java.'], 'inputs': {0: {'preprocessing': {0: {'name': ['Missing data for required field.'], 'scale_range': ['Unknown field.']}}, 'data_range': ['Not a valid tuple.']}}, 'weights': defaultdict(<class 'dict'>, {'keras_hdf5': {'value': [{'authors': {0: {'_schema': ['Invalid input type.']}}, 'weights_format': ['Must be equal to pytorch_state_dict.']}, {'authors': {0: {'_schema': ['Invalid input type.']}}, 'weights_format': ['Must be equal to pytorch_script.']}, {'authors': {0: {'_schema': ['Invalid input type.']}}}, {'authors': {0: {'_schema': ['Invalid input type.']}}, 'weights_format': ['Must be equal to tensorflow_js.']}, {'authors': {0: {'_schema': ['Invalid input type.']}}, 'weights_format': ['Must be equal to tensorflow_saved_model_bundle.']}, {'authors': {0: {'_schema': ['Invalid input type.']}}, 'weights_format': ['Must be equal to onnx.']}]}}), 'outputs': {0: {'data_range': ['Not a valid tuple.'], 'postprocessing': {0: {'name': ['Missing data for required field.'], 'binarize': ['Unknown field.']}}}}, 'type': ['Missing data for required field.'], 'packaged_by': {0: {'_schema': ['Invalid input type.']}}}
I have mad a fixed rdf and will post it in gitter, in case it helps you to debug this. But I think we need to get the validator running for you again; let me know if you still run into issues running it.
I installed the development environment from predict
branch. The installation went well but I can't execute the prediction:
$ bioimageio-predict -m /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/model.yaml -i /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/exampleImage.tif -o /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/resultImage.tif
bioimageio-predict: command not found
The same applies for bioimageio-test
.
I installed the development environment from
predict
branch. The installation went well but I can't execute the prediction:$ bioimageio-predict -m /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/model.yaml -i /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/exampleImage.tif -o /home/esgomezm/Downloads/arabidopsis_03JUN2021.bioimage.io.model/resultImage.tif bioimageio-predict: command not found
The same applies for
bioimageio-test
.
for these entry points to work you need to install this bioimageio.spec package as well (with conda develop .
or pip install -e .
in the root dir of this repository.
I installed it with pip and still doesn't work. It says command not found
(bio-core-dev) esgomezm@esgomezm:~/python-bioimage-io$ pip install -e .
I installed it with pip and still doesn't work. It says
command not found
(bio-core-dev) esgomezm@esgomezm:~/python-bioimage-io$ pip install -e .
does installing spec-bioimage-io (not python-bioimage-io) work?
ehh. that doesn't make sense... hmm.. does python -m bioimageio.core
work for you?
ehh. that doesn't make sense... hmm.. does
python -m bioimageio.core
work for you?
No. Just note that I'm using the predict
branch of the respository
(bio-core-dev) esgomezm@esgomezm:~/python-bioimage-io$ python -m bioimageio.core
bioimageio.core package version 0.4.0
Usage: python -m bioimageio.core [OPTIONS] COMMAND [ARGS]...
Try 'python -m bioimageio.core --help' for help.
Error: Missing command.
@esgomezm the correct command is bioimageio predict
, without the dash and instead with a space in between. If you just type in bioimageio
it should list all the available commands. Could you please try again and see if that works in the env where you have installed the predict branch?
(Edit and also @FynnBe I would like to not advertise the python -m
pattern any more. It does not support autocomplete, so using the bioimageio
is much more conveninent.)
(Edit and also @FynnBe I would like to not advertise the
python -m
pattern any more. It does not support autocomplete, so using thebioimageio
is much more conveninent.)
good point. I just didn't notice the additional dash and was puzzled that it didn't work for her...
(bio-core-dev) esgomezm@esgomezm:~/python-bioimage-io$ python -m bioimageio.core bioimageio.core package version 0.4.0 Usage: python -m bioimageio.core [OPTIONS] COMMAND [ARGS]... Try 'python -m bioimageio.core --help' for help.
Error: Missing command.
this is the expected output though... but try bioimageio predict
as @constantinpape suggested ;-)
We currently have two models exported from zero-cost in the model zoo:
Both do not pass validation with the current spec, see next comments.