Deep learning ModuleNotFoundError:没有名为';fastai.vision';

Deep learning ModuleNotFoundError:没有名为';fastai.vision';,deep-learning,google-colaboratory,fast-ai,Deep Learning,Google Colaboratory,Fast Ai,我正在尝试使用fastai的ImageDataBunch,它运行得很好,但最近当我运行代码时,它显示了以下错误ModuleNotFoundError:没有名为'fastai.vision'的模块 然后,我升级了我的fastai版本pip安装fastai--upgrade 此错误已被清除,但已登录到name错误:未定义名称“ImageDataBunch” import warnings import numpy as np from fastai.vision import * warnings.

我正在尝试使用fastai的ImageDataBunch,它运行得很好,但最近当我运行代码时,它显示了以下错误
ModuleNotFoundError:没有名为'fastai.vision'的模块
然后,我升级了我的fastai版本
pip安装fastai--upgrade

此错误已被清除,但已登录到
name错误:未定义名称“ImageDataBunch”

import warnings
import numpy as np
from fastai.vision import *
warnings.filterwarnings("ignore", category=UserWarning, module="torch.nn.functional")
np.random.seed(42)
data = ImageDataBunch.from_folder(path, train='.', valid_pct=0.2, 
                               ds_tfms=get_transforms(), size=224, num_workers=4, no_check=True).normalize(imagenet_stats)

如何解决这个问题?

当我开始使用Colab时,实际上遇到了同样的问题,但一直无法重现。以下是描述我和另一位开发人员如何进行故障排除的线程:

我建议尝试工厂重置运行时(“运行时”->“工厂重置运行时”)

然后,您可以检查您拥有哪个版本的fastai(如果您已经导入了新版本,则必须重新启动运行时才能使用新版本)


我能够在fastai 1.0.61版和2.0.13版上运行
fastai.vision import*
我的解决方案是复制(连接)我的谷歌硬盘,然后运行单元格

在Google Colab中:

在colab上升级fastai:

! [ -e /content ] && pip install -Uqq fastai 
导入必要的库:

from fastai.vision.all import *
from fastai.text.all import *
from fastai.collab import *
from fastai.tabular.all import * 
获取图像和注释:

path = untar_data(URLs.PETS)
path_anno = path/'annotations'
path_img = path/'images'
print( path_img.ls() )             # print all images
fnames = get_image_files(path_img) # -->> 7390 images
print(fnames[:5])                  # print first 5 images 

谢谢,但我的问题是关于ImageDataBunch的,在尝试了您的解决方案后,我将fastai版本设置为
2.0.13
,但我仍然面临ImageDataBunch错误?fastai升级版是否支持它,如何修复?省去了我这么多的头疼,谢谢!
path = untar_data(URLs.PETS)
path_anno = path/'annotations'
path_img = path/'images'
print( path_img.ls() )             # print all images
fnames = get_image_files(path_img) # -->> 7390 images
print(fnames[:5])                  # print first 5 images