简体   繁体   中英

Attribute error: device in fast.ai learner

I am building a cnn learner using resnet18 with the following code:

from fastai.vision import *

data = (ImageList.from_df(train_df, path='/working/')
   .split_by_rand_pct(0.2)
   .label_from_df(label_delim=','))

learner = cnn_learner(data, models.resnet18, metrics=[accuracy])

I get the following error:

AttributeError Traceback (most recent call last)

AttributeError: device

How can I resolve this?

Try this:

  1. First convert the data into databunch

    data = (ImageList.from_df(train_df, path='/working/').split_by_rand_pct(0.2).label_from_df(label_delim=',').databunch()))

  2. Depending on the hardware. (I am using using cpu for processing).

    import torch data.device = torch.device('cpu')

  3. Call the learner.

    learner = cnn_learner(data, models.resnet18, metrics=[accuracy])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM