我需要测试一些快速模型在没有GPU的环境中,特别是在windows服务器中。我在Google中训练了一些快速模型,现在需要对它们进行实时测试,连接到工业过程中。尽管如此,我对硬件还很有限。
在Google中,我使用了这个配置。
from fastai.vision import *
from fastai.metrics import error_rate
from PIL import Image as PImage
import numpy as np
import cv2
import os
import pandas as pd
第一行是唯一有问题的一行是第一行,我得到了这个错误:
~\.conda\envs\fastai_1\lib\site-packages\fastai\vision\__init__.py", line 3, in <module>
from .learner import *
~\.conda\envs\fastai_1\lib\site-packages\fastai\vision\learner.py", line 6, in <module>
from . import models
~\.conda\envs\fastai_1\lib\site-packages\fastai\vision\models\__init__.py", line 2, in <module>
from torchvision.models import ResNet,resnet18,resnet34,resnet50,resnet101,resnet152
~\.conda\envs\fastai_1\lib\site-packages\torchvision\__init__.py", line 4, in <module>
from .extension import _HAS_OPS
~\.conda\envs\fastai_1\lib\site-packages\torchvision\extension.py", line 51, in <module>
_register_extensions()
~\.conda\envs\fastai_1\lib\site-packages\torchvision\extension.py", line 47, in _register_extensions
torch.ops.load_library(ext_specs.origin)
~\.conda\envs\fastai_1\lib\site-packages\torch\_ops.py", line 99, in load_library
path = torch._utils_internal.resolve_library_path(path)
AttributeError: module 'torch' has no attribute '_utils_internal'
我必须用conda安装Py手电筒,就像Pytorch本地https://pytorch.org/get-started/locally/所建议的那样,但是对于fastai,我必须使用pip安装。Conda在服务器上的有限硬件中不工作
# for Pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
# for fastai
python -m pip install fastai==1.0.61
我的torch版本是1.9.0我的python版本是3.7.7
我检查了几个类似的线程,它们具有不同的属性,但它们都与特定的错误有关,而不是“_utils_internal”。
我很感谢你的帮助
发布于 2022-06-21 12:51:12
我也遇到了同样的问题(Pytorch 1.11.0,Torchvision 0.12.0,CUDA 11.3,Python3.10),并提出了一个有点“无趣”的解决方案。
首先,我检查了给定位置的文件_ops.py,它确实包含语句和函数:
import torch._utils_internal
...
path = torch._utils_internal.resolve_library_path(path)
此外,还提供了_utils_internal.py,并包含以下语句和函数:
import os
...
def resolve_library_path(path: str) -> str:
return os.path.realpath(path)
由于我并不真正理解问题所在,所以我决定将返回的表达式复制到_ops.py文件中并添加os导入。因此,这现在包含:
import os
...
path = os.path.realpath(path)
而且起作用了!
https://stackoverflow.com/questions/68274836
复制相似问题