Skip to content

Commit

Permalink
Assert correct model type when converting, issue #413 (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd authored Mar 18, 2024
1 parent 6eb3fb0 commit 5637438
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Would you like to build/train a model using Keras/Python? And would you like to
Usage
-----

1) Use Keras/Python to build (`model.compile(...)`), train (`model.fit(...)`) and test (`model.evaluate(...)`) your model as usual. Then save it to a single HDF5 file using `model.save('....keras')`. The `image_data_format` in your model must be `channels_last`, which is the default when using the TensorFlow backend. Models created with a different `image_data_format` and other backends are not supported.
1) Use Keras/Python to build (`model.compile(...)`), train (`model.fit(...)`) and test (`model.evaluate(...)`) your model as usual. Then save it to a single file using `model.save('....keras')`. The `image_data_format` in your model must be `channels_last`, which is the default when using the TensorFlow backend. Models created with a different `image_data_format` and other backends are not supported.

2) Now convert it to the frugally-deep file format with `keras_export/convert_model.py`

Expand Down
3 changes: 3 additions & 0 deletions keras_export/convert_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ def workaround_cudnn_not_found_problem():
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)

def assert_model_type(model):
import keras
assert type(model) in [keras.src.models.sequential.Sequential, keras.src.models.functional.Functional]

def convert(in_path, out_path, no_tests=False):
"""Convert any (h5-)stored Keras model to the frugally-deep model format."""
Expand Down

0 comments on commit 5637438

Please sign in to comment.