How do I save an AutoQKeras model that a different script can load?
- Dominant language
- Python
- Stars
- 584
- Forks
- 108
- PR merge metrics
- No merged PRs in 30d
Description
I can't figure out how to get back a model from an AutoQKeras search in one script, when in another script. I tried to use `qmodel.save('qmodel')` and `qmodel = load_qmodel('qmodel')`, but I get these errors.
```
Traceback (most recent call last):
File "code/auto_qkeras.py", line 578, in
aqk_model = load_qmodel('qmodel')
File "/home/berian/.local/lib/python3.8/site-packages/qkeras/utils.py", line 928, in load_qmodel
qmodel = tf.keras.models.load_model(filepath, custom_objects=custom_objects,
File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 1008, in revive_custom_object
raise ValueError(
ValueError: Unable to restore custom object of type _tf_keras_metric. Please make sure that any custom layers are included in the `custom_objects` arg when calling `load_model()` and make sure that all layers implement `get_config` and `from_config`.
```
Following the AutoQKeras guide https://github.com/google/qkeras/blob/master/notebook/AutoQKeras.ipynb, there is an example for saving/loading weights into a QKeras model object. However, I won't have the model object from the AutoQKeras searchin a different script, so using `qmodel.load_weights("qmodel.h5")` is not feasible. I have also noticed that when I make my own QKeras model object, `qmodel.save(...)` and `qmodel = load_qmodel(...)` work just fine.
Maybe there are some extra options I need to add to the`load_qmodel(...)` function? Or is there a better way altogether to transfer qmodel the object from one script to another?
Contributor guide
Research direction
Start with the AutoQKeras.ipynb saving example and qkeras/utils.py around load_qmodel at line 928. Reproduce the qmodel.save and load_qmodel calls across separate scripts, comparing them with the working manually created QKeras model case. Done means an AutoQKeras search result can be saved in one script and loaded in another without the reported custom-object error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100