torchvision避坑指南

2022-06-08 13:49:04 浏览数 (2)

今天使用torchvision进行学习

导入torchvision的时候报错了

代码语言:javascript复制
C:UsersAdministrator>python
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torchvision.datasets
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:pythonlibsite-packagestorchvision__init__.py", line 1, in <module>
    from torchvision import models
  File "D:pythonlibsite-packagestorchvisionmodels__init__.py", line 11, in <module>
    from . import detection
  File "D:pythonlibsite-packagestorchvisionmodelsdetection__init__.py", line 1, in <module>
    from .faster_rcnn import *
  File "D:pythonlibsite-packagestorchvisionmodelsdetectionfaster_rcnn.py", line 7, in <module>
    from torchvision.ops import misc as misc_nn_ops
  File "D:pythonlibsite-packagestorchvisionops__init__.py", line 1, in <module>
    from .boxes import nms, box_iou
  File "D:pythonlibsite-packagestorchvisionopsboxes.py", line 2, in <module>
    from torchvision import _C
ImportError: DLL load failed: 找不到指定的模块。

很明显是torchvision的问题,于是开启了面向百度debug方法

首先说一下百度的解决方案:

  1. 老生常谈,使用conda安装torch和torchvision,说pip安装的时候可能会有什么编译错误或者链接错误。Tom可信指数:3颗星,pip好歹也是一个很牛的工具,而且我费了九牛二虎之力 才用pip安装成功的torchvision,我才不去卸载然后再安装呢。

2.安装一个dll的第三方库,叫做intel-openmp,看到这名字我上去就是一个大写的“漏”,因为根绝我的第三感,不用安装,而且这个方法的提供者说也失败了,所以Tom可信指数:3颗星

这时候,Tom开始着急了,额头紧缩,因为若是把torch和torchvision全卸载了,然后再安装又得耽误好久,网络问题是个大问题。

不管了先看一下 torchvision的版本吧

代码语言:javascript复制
C:UsersAdministrator>pip list
Package                           Version
--------------------------------- -------------------
-ip                               20.1
a2x                               0.0.3
absl-py                           1.0.0
aioredis                          1.3.1
amqp                              2.5.2
appdirs                           1.4.3
argon2-cffi                       19.2.0
arrow                             0.15.5
asgiref                           3.2.7
astunparse                        1.6.3
async-timeout                     3.0.1
atomicwrites                      1.3.0
attrs                             19.3.0
autobahn                          20.6.2
Automat                           0.8.0
backcall                          0.1.0
beautifulsoup4                    4.8.2
billiard                          3.6.3.0
binaryornot                       0.4.4
black                             19.10b0
bleach                            3.1.5
cached-property                   1.5.2
cachetools                        5.0.0
caelum                            0.1.30.21
celery                            4.4.2
certifi                           2019.11.28
cffi                              1.14.0
cfgv                              3.1.0
channels                          2.4.0
channels-redis                    2.4.0
chardet                           3.0.4
Click                             7.0
colorama                          0.4.4
constantly                        15.1.0
cookiecutter                      1.6.0
coverage                          5.1
cqplus-sdk                        1.0.7
cryptography                      2.8
cssselect                         1.1.0
cycler                            0.10.0
daphne                            2.5.0
decorator                         4.4.2
defusedxml                        0.6.0
dill                              0.3.4
distlib                           0.3.0
Django                            2.2
django-allauth                    0.41.0
django-appconf                    1.0.4
django-celery-beat                2.0.0
django-celery-email               3.0.0
django-compressor                 2.4
django-contrib-comments           1.9.2
django-coverage-plugin            1.8.0
django-crispy-forms               1.9.0
django-debug-toolbar              2.2
django-environ                    0.4.5
django-extensions                 2.2.9
django-markdownx                  3.0.1
django-mdeditor                   0.1.14
django-model-utils                4.0.0
django-redis                      4.11.0
django-stubs                      1.5.0
django-taggit                     1.1.0
django-timezone-field             4.0
djangorestframework               3.8.2
docopt                            0.6.2
entrypoints                       0.3
environ                           1.0
ephem                             3.7.7.1
et-xmlfile                        1.0.1
factory-boy                       2.12.0
Faker                             4.0.3
filelock                          3.0.12
flake8                            3.7.9
flake8-isort                      3.0.0
flatbuffers                       2.0
future                            0.18.2
gast                              0.5.3
geographiclib                     1.50
geopy                             2.1.0
google-auth                       2.6.6
google-auth-oauthlib              0.4.6
google-pasta                      0.2.0
grpcio                            1.45.0
h5py                              3.6.0
hiredis                           1.0.1
hyperlink                         19.0.0
identify                          1.4.14
idna                              2.8
importlib-metadata                1.6.0
incremental                       17.5.0
ipdb                              0.13.2
ipykernel                         5.3.4
ipython                           7.13.0
ipython-genutils                  0.2.0
ipywidgets                        7.5.1
jdcal                             1.4.1
jedi                              0.17.0
Jinja2                            2.11.1
jinja2-time                       0.2.0
joblib                            1.1.0
jsonpatch                         1.32
jsonpointer                       2.3
jsonschema                        3.2.0
jupyter                           1.0.0
jupyter-client                    6.1.6
jupyter-console                   6.1.0
jupyter-contrib-core              0.3.3
jupyter-contrib-nbextensions      0.5.1
jupyter-core                      4.6.3
jupyter-highlight-selected-word   0.2.0
jupyter-latex-envs                1.4.6
jupyter-nbextensions-configurator 0.4.1
keras                             2.8.0
Keras-Preprocessing               1.1.2
kiwisolver                        1.3.1
kombu                             4.6.8
libclang                          14.0.1
lxml                              4.4.1
Markdown                          3.2.2
MarkupSafe                        1.1.1
matplotlib                        3.3.4
mistune                           0.8.4
mock                              4.0.3
more-itertools                    8.2.0
msgpack                           0.6.2
multiprocess                      0.70.12.2
mypy                              0.770
mypy-extensions                   0.4.3
mysqlclient                       1.4.6
nbconvert                         5.6.1
nbformat                          5.0.7
nodeenv                           1.3.3
notebook                          6.0.3
numpy                             1.21.6
oauthlib                          3.1.0
opencv-python                     4.5.5.64
openpyxl                          3.0.3
opt-einsum                        3.3.0
packaging                         20.3
pandas                            1.1.1
pandocfilters                     1.4.2
parsel                            1.5.2
parso                             0.7.0
pathspec                          0.8.0
peewee                            3.14.0
pickleshare                       0.7.5
Pillow                            7.1.1
pip                               20.1.1
pipreqs                           0.4.10
pluggy                            0.13.1
poyo                              0.5.0
pre-commit                        2.2.0
prettytable                       2.0.0
prometheus-client                 0.8.0
prompt-toolkit                    3.0.5
Protego                           0.1.16
protobuf                          3.20.1
psycopg2-binary                   2.8.5
py                                1.8.1
pyasn1                            0.4.8
pyasn1-modules                    0.2.8
pycparser                         2.19
PyDispatcher                      2.0.5
pyephem                           9.99
PyExecJS                          1.5.1
pyflakes                          2.1.1
Pygments                          2.6.1
PyHamcrest                        2.0.0
pylint-celery                     0.3
pylint-django                     2.0.15
pylint-plugin-utils               0.6
pymssql                           2.1.5
PyMySQL                           0.9.3
pyOpenSSL                         19.1.0
pyparsing                         2.4.7
pyquery                           1.4.1
pyrsistent                        0.16.0
pytest                            5.3.5
pytest-django                     3.9.0
pytest-sugar                      0.9.2
python-crontab                    2.4.1
python-dateutil                   2.8.1
python-slugify                    4.0.0
python3-openid                    3.1.0
pytz                              2019.3
pywin32                           228
pywinpty                          0.5.7
PyYAML                            5.3.1
pyzmq                             19.0.1
qtconsole                         4.7.5
QtPy                              1.9.0
queuelib                          1.5.0
rcssmin                           1.0.6
redis                             3.4.1
regex                             2020.4.4
requests                          2.22.0
requests-oauthlib                 1.3.0
rjsmin                            1.1.0
rsa                               4.8
scikit-learn                      1.0.2
scipy                             1.6.0
Scrapy                            1.8.0
selenium                          3.141.0
Send2Trash                        1.5.0
service-identity                  18.1.0
setuptools                        41.2.0
six                               1.14.0
sklearn                           0.0
solpy                             0.13.30.21
sorl-thumbnail                    12.6.3
soupsieve                         1.9.5
SQLAlchemy                        1.3.22
sqlparse                          0.3.0
tensorboard                       2.8.0
tensorboard-data-server           0.6.1
tensorboard-plugin-wit            1.8.1
tensorboardX                      2.5
tensorflow                        2.8.0
tensorflow-io-gcs-filesystem      0.25.0
termcolor                         1.1.0
terminado                         0.8.3
testfixtures                      6.14.0
testpath                          0.4.4
text-unidecode                    1.3
tf-estimator-nightly              2.8.0.dev2021122109
threadpoolctl                     3.1.0
toml                              0.10.0
torch                             1.9.0 cu102
torchfile                         0.1.0
torchvision                       0.3.0
tornado                           6.0.4
traitlets                         4.3.3
Twisted                           19.10.0
txaio                             20.4.1
typing-extensions                 3.7.4.2
urllib3                           1.25.8
vine                              1.3.0
virtualenv                        20.0.18
visdom                            0.1.8.9
w3lib                             1.21.0
wcwidth                           0.1.9
webencodings                      0.5.1
websocket-client                  1.3.2
Werkzeug                          1.0.1
wheel                             0.34.2
whichcraft                        0.6.1
widgetsnbextension                3.5.1
wrapt                             1.14.1
xlrd                              1.2.0
xlwt                              1.3.0
yarg                              0.1.9
zipp                              3.1.0
zope.interface                    4.7.1

234行 可以发现torchvision的版本是0.3.0

这时候突发奇想,要不升个级试试?

因为网上有的debug贴说要安装0.4.0的

说干就干,卸载0.3.0的

然后pip安装0.4.0的

然后再次导入

yesssssir

成功

接下来就开始torchvision之旅吧

let's GO!

0 人点赞