【问题标题】:Why am I getting this error when loading weights?为什么加载重量时出现此错误?
【发布时间】:2022-12-12 07:09:32
【问题描述】:
# Load the hdf5 files
resnet50 = h5py.File('/content/RestNet 50 best_model.hdf5', 'r')
ourmodel = h5py.File('/content/best_model.hdf5', 'r')
resnet152 = h5py.File('/content/best_model_4.hdf5', 'r')

# Get the predictions from each model
predictions1 = resnet50.predict(images)
predictions2 = ourmodel.predict(images)
predictions3 = resnet152.predict(images)

# Combine the predictions using a majority vote
predictions = np.array([predictions1, predictions2, predictions3])
predictions = np.mean(predictions, axis=0)
print(predictions)

错误是

OSError:无法打开文件(截断文件:eof = 225443840,sblock->base_addr = 0,stored_eof = 245806944)

【问题讨论】:

  • 你应该使用tf.keras.models.load_model而不是h5py.File加载模型
  • @V.M 这不是问题所在,问题是为什么会出现错误。
  • 问题是这些 HDF5 文件之一已损坏或不完整(如部分下载),您从哪里得到它们?

标签: python tensorflow machine-learning keras deep-learning


【解决方案1】:

OSError:无法打开文件(截断的文件:eof = 225443840, sblock->base_addr = 0, stored_eof = 245806944)

这意味着您的文件已损坏。预计为 245806944 字节,但在读取 225443840 字节后就结束了。唯一的选择是重新下载它或找到一个未损坏的文件。这种情况经常发生,如果你的连接在下载时中断或者你自己训练它,你的进程在它完成将文件写入磁盘之前就停止了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-13
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 2019-11-03
    • 2017-08-08
    相关资源
    最近更新 更多