首页 > 解决方案 > Fast.ai:ModuleAttributeError: 'Sequential' 对象没有属性 'fine_tune'

问题描述

当我使用fast.ai时,T遇到这个问题,下面是我的代码:

from fastai.vision.all import *
from fastai.text.all import *
from fastai.collab import *
from fastai.tabular.all import *

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

path = untar_data(URLs.PETS)/'images'

def is_cat(x): return x[0].isupper()

dls = ImageDataLoaders.from_name_func(
    path, get_image_files(path), valid_pct=0.2, seed=42,
    label_func=is_cat, item_tfms=Resize(224))

learn = cnn_learner(dls, resnet34, metrics=error_rate).to(device)

learn.fine_tune(1)

它显示:“ModuleAttributeError:'Sequential' 对象没有属性 'fine_tune'”

标签: pythonpytorchimage-classification

解决方案


如果可用,fastai 将为您选择 GPU。

我重现了您的问题,并摆脱.to(device)了 Learner 中的呼叫,从而消除了错误:

learn = cnn_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)

推荐阅读