fastai学习——第一个bug
作者:互联网
跟着视频学习,在运行第一段测试代码的时候出现问题
from fastai.vision.all import *
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)
learn.fine_tune(1)
报错
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
貌似是由于windows引起的,作者诚不欺我
百度无果后去官方论坛搜索,发现解决方案:
打开"./anaconda/envs/fastai/Lib/sitepackages/fastai/data/load.py"
搜索to_device
将
if self.device is not None and multiprocessing.get_start_method().lower() == "fork":
b = to_device(b, self.device)
改为
if self.device is not None:
b = to_device(b, self.device)
修改后正常运行
论坛链接:https://forums.fast.ai/t/part1-2020-02-production-found-at-least-two-devices-cuda-0-and-cpu/87253/7
标签:第一个,get,self,fastai,found,device,path,bug 来源: https://blog.csdn.net/m_zwa/article/details/116585620