gpt4 book ai didi

python - 无法加载检查点的数据

转载 作者:行者123 更新时间:2023-12-05 02:47:57 28 4
gpt4 key购买 nike

我正在按照此处的代码学习使用转换器模型的文本摘要任务,It can be found here

但是代码没有提供训练后加载模型的方法,所以很不方便,我决定写那个函数

这是我所做的:

model = Transformer(
num_layers,
d_model,
num_heads,
dff,
encoder_vocab_size,
decoder_vocab_size,
pe_input=max_len_news,
pe_target=max_len_summary,
)

input = tf.random.uniform([1, 12], 0, 100, dtype=tf.int32) #create dummy input
enc_padding_mask, look_ahead_mask, dec_padding_mask = create_masks(input, input) # create masks
a = model(input, input, False, enc_padding_mask, look_ahead_mask, dec_padding_mask) # call the model before loading weights

model.load_weights('checkpoints/ckpt-5.data-00000-of-00001')

现在,它抛出一个错误:

/usr/local/lib/python3.6/dist-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
171 if swmr and swmr_support:
172 flags |= h5f.ACC_SWMR_READ
--> 173 fid = h5f.open(name, flags, fapl=fapl)
174 elif mode == 'r+':
175 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (file signature not found)

我对机器学习和 TensorFlow 完全陌生。请帮忙。

最佳答案

查看 documentation of tf.keras.Model.load_weights (强调是我的):

Arguments

filepath String, path to the weights file to load. For weight files in TensorFlow format, this is the file prefix (the same as was passed to save_weights).

只需要传递前缀,所以

model.load_weights("checkpoints/ckpt-5")

应该可以解决问题。

关于python - 无法加载检查点的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64693938/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com