2323except ImportError :
2424 torch_converter = None
2525
26+ try :
27+ from bioimageio .core .weight_converter import keras as keras_converter
28+ except ImportError :
29+ keras_converter = None
30+
2631
2732# extend help/version string by core version
2833help_version_core = f"bioimageio.core { __version__ } "
@@ -231,7 +236,8 @@ def convert_torch_weights_to_onnx(
231236 use_tracing : bool = typer .Option (True , help = "Whether to use torch.jit tracing or scripting." ),
232237 verbose : bool = typer .Option (True , help = "Verbosity" ),
233238 ) -> int :
234- return torch_converter .convert_weights_to_onnx (model_rdf , output_path , opset_version , use_tracing , verbose )
239+ ret_code = torch_converter .convert_weights_to_onnx (model_rdf , output_path , opset_version , use_tracing , verbose )
240+ sys .exit (ret_code )
235241
236242 convert_torch_weights_to_onnx .__doc__ = torch_converter .convert_weights_to_onnx .__doc__
237243
@@ -249,5 +255,21 @@ def convert_torch_weights_to_torchscript(
249255 convert_torch_weights_to_torchscript .__doc__ = torch_converter .convert_weights_to_pytorch_script .__doc__
250256
251257
258+ if keras_converter is not None :
259+
260+ @app .command ()
261+ def convert_keras_weights_to_tensorflow (
262+ model_rdf : Path = typer .Argument (
263+ ..., help = "Path to the model resource description file (rdf.yaml) or zipped model."
264+ ),
265+ output_path : Path = typer .Argument (..., help = "Where to save the tensorflow weights." ),
266+ ) -> int :
267+ ret_code = keras_converter .convert_weights_to_tensorflow_saved_model_bundle (model_rdf , output_path )
268+ sys .exit (ret_code )
269+
270+ convert_keras_weights_to_tensorflow .__doc__ = \
271+ keras_converter .convert_weights_to_tensorflow_saved_model_bundle .__doc__
272+
273+
252274if __name__ == "__main__" :
253275 app ()
0 commit comments