MSF
tensorflow
config_error
ai_generated
true
ValueError: Unknown model format: 'h5'. Supported formats: 'tf', 'keras'
ID: tensorflow/unknown-model-save-format
90%Fix Rate
88%Confidence
1Evidence
2023-11-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| tensorflow 2.13.0 | active | — | — | — |
| tensorflow 2.14.0 | active | — | — | — |
Root Cause
Saving a model with .h5 extension is not supported in TF2's default save format; only SavedModel or Keras native format is allowed.
generic中文
在TF2默认保存格式中不支持使用.h5扩展名保存模型;只允许SavedModel或Keras原生格式。
Official Documentation
https://www.tensorflow.org/guide/keras/save_and_serializeWorkarounds
-
95% success Use model.save('my_model.keras') with the native Keras format.
Use model.save('my_model.keras') with the native Keras format. -
90% success Use model.save('my_model', save_format='tf') for SavedModel format.
Use model.save('my_model', save_format='tf') for SavedModel format. -
85% success Explicitly set save_format='h5' in model.save() to force HDF5: model.save('my_model.h5', save_format='h5')
Explicitly set save_format='h5' in model.save() to force HDF5: model.save('my_model.h5', save_format='h5')
中文步骤
Use model.save('my_model.keras') with the native Keras format.Use model.save('my_model', save_format='tf') for SavedModel format.Explicitly set save_format='h5' in model.save() to force HDF5: model.save('my_model.h5', save_format='h5')
Dead Ends
Common approaches that don't work:
-
60% fail
Renaming file extension to .tf doesn't change underlying format.
-
90% fail
Installing h5py doesn't add .h5 support to TF2 save API.