I'm following the code from here to learn the text summarization task with transformer model, It can be found here
But the code doesn't provide a way to load a model after training, so It's an inconvenience and I decided to write that function
Here is what I have done:
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')
Now, It throws an error:
/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)
I'm totally new to machine learning and TensorFlow. Please help.
Looking at the documentation of tf.keras.Model.load_weights (emphasis is mine):
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).
You only need to pass the prefix, so
model.load_weights("checkpoints/ckpt-5")
should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With