Skip to content

Commit

Permalink
Merge pull request #404 from bioimage-io/bump_release
Browse files Browse the repository at this point in the history
bump patch
  • Loading branch information
FynnBe authored Jul 18, 2024
2 parents e680c0e + 96e06b6 commit 3179f83
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ The model specification and its validation tools can be found at <https://github

## Changelog

### 0.6.8 (to be released)
### 0.6.8

* testing model inference will now check all weight formats
(previously only the first one for which model adapter creation succeeded had been checked)
* fix predict with blocking (Thanks @thodkatz)

### 0.6.7

Expand Down
2 changes: 1 addition & 1 deletion bioimageio/core/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.6.7"
"version": "0.6.8"
}
38 changes: 26 additions & 12 deletions bioimageio/core/model_adapters/_model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ def create(
)

weights = model_description.weights
errors: List[str] = []
errors: List[Tuple[WeightsFormat, Exception]] = []
weight_format_priority_order = (
DEFAULT_WEIGHT_FORMAT_PRIORITY_ORDER
if weight_format_priority_order is None
else weight_format_priority_order
)
# limit weight formats to the ones present
weight_format_priority_order = [
w for w in weight_format_priority_order if getattr(weights, w) is not None
]

for wf in weight_format_priority_order:
if wf == "pytorch_state_dict" and weights.pytorch_state_dict is not None:
try:
Expand All @@ -77,7 +82,7 @@ def create(
devices=devices,
)
except Exception as e:
errors.append(f"{wf}: {e}")
errors.append((wf, e))
elif (
wf == "tensorflow_saved_model_bundle"
and weights.tensorflow_saved_model_bundle is not None
Expand All @@ -89,7 +94,7 @@ def create(
model_description=model_description, devices=devices
)
except Exception as e:
errors.append(f"{wf}: {e}")
errors.append((wf, e))
elif wf == "onnx" and weights.onnx is not None:
try:
from ._onnx_model_adapter import ONNXModelAdapter
Expand All @@ -98,7 +103,7 @@ def create(
model_description=model_description, devices=devices
)
except Exception as e:
errors.append(f"{wf}: {e}")
errors.append((wf, e))
elif wf == "torchscript" and weights.torchscript is not None:
try:
from ._torchscript_model_adapter import TorchscriptModelAdapter
Expand All @@ -107,7 +112,7 @@ def create(
model_description=model_description, devices=devices
)
except Exception as e:
errors.append(f"{wf}: {e}")
errors.append((wf, e))
elif wf == "keras_hdf5" and weights.keras_hdf5 is not None:
# keras can either be installed as a separate package or used as part of tensorflow
# we try to first import the keras model adapter using the separate package and,
Expand All @@ -125,15 +130,24 @@ def create(
model_description=model_description, devices=devices
)
except Exception as e:
errors.append(f"{wf}: {e}")
errors.append((wf, e))

assert errors
error_list = "\n - ".join(errors)
raise ValueError(
"None of the weight format specific model adapters could be created for"
+ f" '{model_description.id or model_description.name}'"
+ f" in this environment. Errors are:\n\n{error_list}.\n\n"
)
if len(weight_format_priority_order) == 1:
assert len(errors) == 1
raise ValueError(
f"The '{weight_format_priority_order[0]}' model adapter could not be created"
+ f" in this environment:\n{errors[0][1].__class__.__name__}({errors[0][1]}).\n\n"
)

else:
error_list = "\n - ".join(
f"{wf}: {e.__class__.__name__}({e})" for wf, e in errors
)
raise ValueError(
"None of the weight format specific model adapters could be created"
+ f" in this environment. Errors are:\n\n{error_list}.\n\n"
)

@final
def load(self, *, devices: Optional[Sequence[str]] = None) -> None:
Expand Down

0 comments on commit 3179f83

Please sign in to comment.