TypeError: __init__() got an unexpected keyword argument 'filepath'

Viewed 6038

I don't know how to solve this error but I hope some of you guys know how to solve this issue.

Error:TypeError: __init__() got an unexpected keyword argument 'filepath'

Full error message:

  File "train.py", line 167, in <module>
    main(args)
  File "train.py", line 113, in main
    checkpoint_callback=checkpoint_callback(),
  File "train.py", line 86, in checkpoint_callback
    return ModelCheckpoint(
TypeError: __init__() got an unexpected keyword argument 'filepath'
from pytorch_lightning.callbacks import ModelCheckpoint

save_model_path = path/to/your/dir
def checkpoint_callback():
    return ModelCheckpoint(
        filepath= save_model_path,
        save_top_k=True,
        verbose=True,
        monitor='val_loss',
        mode='min',
        prefix=''
    )
2 Answers

ModelCheckpoint doesn't have a filepath keyword, it does however have a dirpath keyword (as you can see in the documentation), replace filepath with dirpath, like this:

from pytorch_lightning.callbacks import ModelCheckpoint

save_model_path = path/to/your/dir
def checkpoint_callback():
    return ModelCheckpoint(
        dirpath=save_model_path, # changed line
        save_top_k=True,
        verbose=True,
        monitor='val_loss',
        mode='min',
        prefix=''
    )

The version of pytorch_lightning is too high or too low. The api definition is changed

CLASS pytorch_lightning.callbacks.model_checkpoint.ModelCheckpoint(dirpath=None, filename=None,
monitor=None, verbose=False, save_last=None, save_top_k=1, save_weights_only=False,
mode='min', auto_insert_metric_name=True, every_n_train_steps=None, train_time_interval=None,
every_n_epochs=None, save_on_train_epoch_end=None, period=None, every_n_val_epochs=None)
Related