Skip to content

ValueError: The filepath provided must end in .keras (Keras model format). Received: filepath=Models/02_captcha_to_text/202403291006/model.h5 #48

Description

@keosaly

Hello,
Can you help me to fix this?

ValueError: The filepath provided must end in .keras (Keras model format). Received: filepath=Models/02_captcha_to_text/202403291006/model.h5

Activity

  1. keosaly commented on Mar 29, 2024

    @keosaly
    Author

    my code:

    Define callbacks

    earlystopper = EarlyStopping(monitor="val_CER", patience=50, verbose=1, mode="min")
    checkpoint = ModelCheckpoint(f"{configs.model_path}/model.h5", monitor="val_CER", verbose=1, save_best_only=True, mode="min")
    trainLogger = TrainLogger(configs.model_path)
    tb_callback = TensorBoard(f"{configs.model_path}/logs", update_freq=1)
    reduceLROnPlat = ReduceLROnPlateau(monitor="val_CER", factor=0.9, min_delta=1e-10, patience=20, verbose=1, mode="min")
    model2onnx = Model2onnx(f"{configs.model_path}/model.h5")

    Train the model

    model.fit(
    train_data_provider,
    validation_data=val_data_provider,
    epochs=configs.train_epochs,
    callbacks=[earlystopper, checkpoint, trainLogger, reduceLROnPlat, tb_callback, model2onnx],
    workers=configs.train_workers
    )

    Save training and validation datasets as csv files

    train_data_provider.to_csv(os.path.join(configs.model_path, "train.csv"))
    val_data_provider.to_csv(os.path.join(configs.model_path, "val.csv"))

  2. mbahadirk commented on May 7, 2024

    @mbahadirk

    did you find any solutions on that?
    I'am still working on that

  3. pythonlessons commented on May 16, 2024

    @pythonlessons
    Owner

    It seems you try to use newest tensorflow version (different from tutorial). Recommend to downgrade tensorflow for compatibility. Otherwise you need to do changes manualy. For example change model.h5 to model.keras in all places. But you may face more serious incompatibilities further

  4. Mudr0x commented on Aug 8, 2024

    @Mudr0x

    In Keras 3, for checkpoint filepath, you need to provide in .keras format only, if you're saving only weights file name should end with .weights.h5, so if you want to save your model in .h5 file in any case, set "save_weights_only=True", and change your flie name to "xxx.weights.h5".
    https://keras.io/guides/migrating_to_keras_3/#saving-a-model-in-the-tf-savedmodel-format

    keras-team/keras-io#1844

    Here's changes for your code:

    earlystopper = EarlyStopping(monitor="val_CER", patience=50, verbose=1, mode="min")
    checkpoint = ModelCheckpoint(f"{configs.model_path}/model.h5", monitor="val_CER", verbose=1, save_best_only=True,, save_weights_only=True, mode="min")
    trainLogger = TrainLogger(configs.model_path)
    tb_callback = TensorBoard(f"{configs.model_path}/logs", update_freq=1)
    reduceLROnPlat = ReduceLROnPlateau(monitor="val_CER", factor=0.9, min_delta=1e-10, patience=20, verbose=1, mode="min")
    model2onnx = Model2onnx(f"{configs.model_path}/model.h5")
    
    model.fit(
    train_data_provider,
    validation_data=val_data_provider,
    epochs=configs.train_epochs,
    callbacks=[earlystopper, checkpoint, trainLogger, reduceLROnPlat, tb_callback, model2onnx]
    )
    
    train_data_provider.to_csv(os.path.join(configs.model_path, "train.csv"))
    val_data_provider.to_csv(os.path.join(configs.model_path, "val.csv"))
    
  5. maxima120 commented on Feb 2, 2025

    @maxima120

    I have the same problem. I want to save in "tensorflow" format - which is set of files in a directory. I do not want to use either .keras nor .h5

    I want to save everything not just weights. And I want to use it for both - future training and inference.

    If i save it in .keras format - when I load it for further training or inference, sometimes it throws - optimiser variables mismatch, and doesnt use the saved adam vars.

    Which I want to avoid (tell me this is wrong idea).

    Versions:
    TF Version: 2.18.0
    Python Version: 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0]

    I use tf.keras everywhere not keras directly (if it makes any difference).

    What happened to the "tensorflow" checkpoints? have you removed this feature completely? I dont see anything in the docs indicating it and the samples that supposed to use tensorflow format are throwing the same error (want .keras suffix - in either - checkpoint callback and direct model.save)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions