【问题标题】:Fast.ai:ModuleAttributeError: 'Sequential' object has no attribute 'fine_tune'Fast.ai:ModuleAttributeError: 'Sequential' 对象没有属性 'fine_tune'
【发布时间】:2021-04-19 01:23:46
【问题描述】:

我用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'”

【问题讨论】:

  • learn.fit_one_cycle 的类似问题,但错误是“没有属性'fit_one_cyle'”

标签: python pytorch image-classification


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-28
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多