Cannot load model weights in TensorFlow: File format not supported

At the call

I get this error

ValueError: File format not supported: filepath=I:\resnet50\e_8_b_20000.ckpt.
Keras 3 only supports V3 `.keras` and `.weights.h5` files, or legacy V1/V2 `.h5` files.

model was saved with
model.save_weights('checkpoints/{}/e_{}_b_{}.ckpt'.format(model_name, epochs, steps % steps_per_epoch))

and consists of these files


I’m using tensorflow 2.16 Same code and model files works in tensorflow 2.1 and I see from documentation here in the section Manually save weights
That by default, tf.keras and Model.save_weights method in particular—uses the TensorFlow Checkpoint format with a .ckpt extension.

So it seems Checkpoint format with a .ckpt extension is still supported.

Hi @AndrewFar, This is due to, from tensorflow 2.16 the default keras version is 3.0. while loading weights from the checkpoints the extension for ckpt file should be .weights.h5 but I can see you have saved the ckpt in .ckpt format. when loading the using this .ckpt file causes this error. while saving the please try to save them us .weights.h5. extension while using tf2.16.

model.save_weights('checkpoints/{}/e_{}_b_{}.weights.h5'.format(model_name, epochs, steps % steps_per_epoch))

please refer to this gist for working code example. Thank You.

1 Like