MSF
tensorflow
config_error
ai_generated
true
值错误:未知模型格式 'h5'。支持的格式:'tf', 'keras'
ValueError: Unknown model format: 'h5'. Supported formats: 'tf', 'keras'
ID: tensorflow/unknown-model-save-format
90%修复率
88%置信度
1证据数
2023-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| tensorflow 2.13.0 | active | — | — | — |
| tensorflow 2.14.0 | active | — | — | — |
根因分析
在TF2默认保存格式中不支持使用.h5扩展名保存模型;只允许SavedModel或Keras原生格式。
English
Saving a model with .h5 extension is not supported in TF2's default save format; only SavedModel or Keras native format is allowed.
官方文档
https://www.tensorflow.org/guide/keras/save_and_serialize解决方案
-
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')
无效尝试
常见但无效的做法:
-
60% 失败
Renaming file extension to .tf doesn't change underlying format.
-
90% 失败
Installing h5py doesn't add .h5 support to TF2 save API.