在运行文件h5py.py的时候报错:partially initialized module 'h5py' has no attribute 'File' (most likely due to a circular import)
结果发现是因为文件名字和库名一样了,导致的报错,改个名就好了
一个简单的查看模型的代码:
import h5py
model_path = 'model.h5'
# 读取模型文件
with h5py.File(model_path, 'r') as f:
# 打印 HDF5 文件中的所有内容
print("HDF5 file contents:")
print(list(f.keys()))
# 查看模型的结构和属性
if 'model_weights' in f:
print("\nModel weights:")
for key in f['model_weights']:
print(key)
if 'model_config' in f:
print("\nModel config:")
model_config = f['model_config'].value
print(model_config)