pytorch 类型错误:__init__()缺少1个必需的位置参数:'filepath'?

q5lcpyga  于 2023-04-06  发布在  其他
关注(0)|答案(1)|浏览(184)

我正在训练一个多标签文本分类,我正在使用PyTorch Lightning来训练模型。
下面是代码:

checkpoint_callback = ModelCheckpoint(
dirpath="checkpoints",
filename="best-checkpoint",
save_top_k=1,
verbose=True,
monitor="val_loss",
mode="min"
)```

And i'm getting

---------------------------------------------------------------------------

`TypeError                                 Traceback (most recent call last)
\<ipython-input-73-9e7c38808397\> in \<cell line: 1\>()
\----\> 1 checkpoint_callback = ModelCheckpoint(
2   dirpath="checkpoints",
3   filename="best-checkpoint",
4   save_top_k=1,
5   verbose=True,
TypeError: __init__() missing 1 required positional argument: 'filepath'`
`how to fix it?`
vq8itlhq

vq8itlhq1#

很奇怪,也许你安装错误的pytorch lightning .我试过这个在colab和没有错误:

!pip install lightning

import lightning.pytorch as pl
checkpoint_callback = pl.callbacks.ModelCheckpoint(
    dirpath="checkpoints",
    filename="best-checkpoint",
    save_top_k=1,
    verbose=True,
    monitor="val_loss",
    mode="min"
)

检查是否正确导入。

相关问题