我正在尝试使用fastai的ImageDataBunch,它工作得很好,但是最近当我运行我的代码时,它显示了这个错误ModuleNotFoundError: No module named 'fastai.vision'然后,我升级了我的fastai版本pip install fastai --upgrade。
此错误已清除,但已登录到NameError: name 'ImageDataBunch' is not defined中
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)如何解决这个问题?
发布于 2020-09-24 18:10:44
实际上,当我开始使用Colab时,我也遇到了同样的问题,但一直无法重现。下面这个线程描述了我和另一个开发人员为解决问题所做的工作:https://forums.fast.ai/t/no-module-named-fastai-data-in-google-colab/78164/4
我建议尝试出厂重置运行时(“运行时”->“出厂重置运行时”)
然后,您可以检查您拥有哪个版本的fastai (如果您已经导入了新版本,则必须重新启动运行时才能使用它)
import fastai
fastai.__version__我可以在fastai版本1.0.61和2.0.13上运行fastai.vision import *
发布于 2021-03-04 00:05:00
发布于 2021-04-30 20:18:19
在Google Colab中:
在colab上快速升级:
! [ -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 https://stackoverflow.com/questions/64039536
复制相似问题