how to load weights (saved using callbacks) in R

I could save weights in each epoch during training using keras R. I have attached code for callback_model_checkpoints() and fit() -

  # callbacks to save weights in each epoch
  callback_model_checkpoint(
    filepath = "weights.{epoch:02d}-{val_acc:.2f}.hdf5",
    monitor = "val_loss",
    verbose = 0,
    save_best_only = TRUE,
    save_weights_only = TRUE,
    mode = c("auto", "min", "max"),
    period = NULL,
    save_freq = "epoch"
  )
  
  # fitting the model on the training dataset
  model %>% 
    fit(train_x, train_y, 
        epochs = 150, batch_size = 1024,
        validation_split = 0.2, verbose = 0,
        callbacks = list(callback_model_checkpoint("checkpoints.h5")))

But how do I load the weights for further diagnosis? I can see a file 'checkpoints.h5' in the working folder.

keras::load_model_weights_hdf5() or keras::load_model_hdf5(), depending on whether save_weights_only is TRUE or FALSE in callback_model_checkpoint(), respectively.

thanks for replying @mattwarkentin

But I am getting errors. I am in the same working directory and there exist a file with name 'checkpoints.h5' -

keras::load_model_weights_hdf5("checkpoints.h5")
Error in normalize_path(filepath) : 
  argument "filepath" is missing, with no default

keras::load_model_hdf5("checkpoints.h5")
 Error in py_call_impl(callable, dots$args, dots$keywords) : 
  AttributeError: 'str' object has no attribute 'decode'

Can you try load_model_hdf5("checkpoints.h5", compile = FALSE)?

hi, I am getting error

load_model_weights_hdf5("checkpoints.h5", compile = FALSE)
Error in load_model_weights_hdf5("checkpoints.h5", compile = FALSE) : 
  unused argument (compile = FALSE)

load_model_hdf5("checkpoints.h5", compile = FALSE)
 Error in py_call_impl(callable, dots$args, dots$keywords) : 
  AttributeError: 'str' object has no attribute 'decode' 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.