[深度学习 - 目标检测 ] yolact 环境配置

1. 准备

1.1. 代码库

https://github.com/dbolya/yolact


1.2. 编译教程

  1. 教程一

https://www.bilibili.com/video/av243457426/

  1. 教程二

https://blog.csdn.net/excelNo1/article/details/122228942

  1. 教程三

https://blog.csdn.net/qq_41915882/article/details/119971992?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-4.queryctrv4&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-4.queryctrv4&utm_relevant_index=6


1.3. 依赖环境

1.3.1. 安装 Conda

  1. 资源路径

https://docs.conda.io/en/latest/miniconda.html

  1. 添加 Anaconda 环境变量

D:\DevlopmentSoftwares\Anaconda3\Scripts
D:\DevlopmentSoftwares\Anaconda3
D:\DevlopmentSoftwares\Anaconda3\Library\bin

  1. Conda入门

https://blog.csdn.net/chenfeidi1/article/details/80873993?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164620346016780265470389%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=164620346016780265470389&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-80873993.first_rank_v2_pc_rank_v29&utm_term=Conda&spm=1018.2226.3001.4187

  1. 使用国内 conda 软件源加速:

https://mirrors.ustc.edu.cn/help/anaconda.html

1.3.2. 安装 CUDA

https://www.cnblogs.com/liuyihai/p/9310909.html


2. 操作

2.1. 源码及模型准备:

  1. 下载教程一中的源码:yolact_tutorials;
  2. 下载测试模型:yolact_base_54_800000.pth .

2.2. 打开Anaconda Prompt,创建一个虚拟环境:

conda create -n yolact python=3.7  //环境名为yolact ,python版本选择3.7
conda activate yolact              //激活yolact 环境

2.3. 安装所需要的依赖:

pip install cython
pip install opencv-python
pip install pillow
pip install pycocotools#用此方式:pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
pip install matplotlib 

2.4. 安装pytorch与torchvision:

安装pytorch时需要先去查看自己的cuda版本:

nvcc --version

然后选择适配 的pytorch版本,pytorch官网:https://pytorch.org/;

# ROCM 4.0.1 (Linux only)
pip install torch==1.8.1+rocm4.0.1 torchvision==0.9.1+rocm4.0.1 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 3.10 (Linux only)
pip install torch==1.8.1+rocm3.10 torchvision==0.9.1+rocm3.10 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 11.1
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2 
pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.1
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

举例:我的CUDA版本是11.1,选择:

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

2.5. 检测pytorch安装结果,显示如下结果则成功:

python
>>> import torch
>>> print(torch.cuda.is_available())
True
>>> print(torch.version.cuda)
11.1

2.6. 测试

  1. 在yolact-master文件夹内新建文件夹weights,将下载好的模型yolact_base_54_800000.pth拷贝进去;
  2. 打开Anaconda Prompt;
  3. 激活yolact 环境;
conda activate yolact
  1. 进入到yolact-master路径下:
cd E:\Dev\Demo\yolact_tutorials\yolact-master
  1. 运行如下代码即可:
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --image=test.jpg
  1. 效果:
    [深度学习 - 目标检测 ] yolact 环境配置_第1张图片

2.1. 编译过程中遇到的问题

2.1.1.

执行

conda activate yolact

出错:

CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.
If using ‘conda activate’ from a batch script, change your
invocation to ‘CALL conda.bat activate’.

参考:

https://www.cnblogs.com/lf-cs/p/12506900.html

解决方法是,先跑一下:

source deactivate

然后服务器应该会提示你:这个命令已经过时了,推荐你用以下命令:

conda deactivate

2.1.2.

执行

conda install pytorch torchvision cudatoolkit=11.1 

出错

Solving environment: failed with initial frozen solve. Retrying with flexible solve

参考:

https://blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/112726892

或:
在 pytorch 官网(https://pytorch.org/)选择合适版本将命令替换如下

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch

你可能感兴趣的:(目标检测,深度学习,目标检测,深度学习)