安装pytorch
- 通过配置文件来安装,但是这样安装特别容易报错,不如直接一个一个安装
- 直接下载到本地安装会比较方便。下载地址:链接: link,直接去寻找对应的版本下载即可
- 在线安装之前配置镜像源
# 添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# 添加阿里云镜像源
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/free/
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main/
# 添加中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
# 查看目前下载的源
conda config --set show_channel_urls yes
#删除源 defaults应该是所有源吧
conda config --remove channels defaults
conda config --remove channels https://mirrors.aliyun.com/anaconda/pkgs/free/
- 本地安装 先将bz2文件移动到anaconda3/pkgs/里面,然后cd 到pkgs文件目录下,使用下面指令。其实也可以不用移动,但是要把路径写清楚,把yourpkgname改为路径
// An highlighted block
conda install --use-local your-pkg-name
5.在导入torch时报错,OSError: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory。解决办法链接: link
6.测试torch是否可以使用gpu.print(torch.cuda.is_available()).输出true即可使用
安装其他所需要的包
- 安装cv2遇到问题,pip install opencv-python (难怪cv2找不到)。下载大的包经常会下载失败,所以去网站下到本地吧。opencv下载链接。里面有很多版本,要看懂的话需要了解一下pip指令
- pip是一个管理包的软件,执行它的时候会去PYPI社区寻找需要的包,pip默认是下载最新的安装包,同时pip也需要更新,pip里面有很多接口,当它更新时,会把一些新的包加进来,把一些旧版本的包删除,所以有时候需要把pip降版本。
#降版本
python -m pip install pip==19.0
#查看版本
pip --version
#更新
python -m pip install --upgrade pip
#查看安装的包
pip list
#生成requirement.txt
pip freeze > requirement.txt #freeze是格式化输出包的版本
cat requirement.txt
pip install -r requirment.txt #根据要求下载包
#查看帮助文档
pip help
#查看pip所支持下载的接口
import pip._internal
print(pip._internal.pep425tags.get_supported())
#如果出现没有这个属性,那就是pip版本太高,降低版本后就好了,可以找到。然后根据输出的内容就可以找到对应可以下载的cv2的版本号了
- 换源安装 pip install -i https://anacond.org opencv-python(记忆中直接把网址放最后也可以)
运行测试文件
- 下载模型,去github上下载对应的权重,建立文件夹models,将下载好的模型放进去
- 运行指令
python test_simple.py --image_path assets/test_image.jpg --model_name mono_640x192