Anaconda3安装可以参考Deeplabv3+ 环境配置-Anaconda3 + Pytorch1.8 + Cuda10.1 + opencv3.2.0
环境配置
- 首先为pytorch创建一个anaconda虚拟环境,环境名字可自己确定,这里使用 yolact++ 作为环境名:
$ conda create -n yolact++ python==3.8
- 安装成功后激活yolact++环境
$ source activate
$ conda activate yolact++
- 在所创建的环境下安装pytorch,查看本机cuda版本
$ conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
$ conda install cudnn=7.6.5
注意:10.2处应为cuda的安装版本号
编辑~./bashrc文件,设置使用yolact++环境下的python3.8
alias python='~/anaconda3/envs/yolact++/bin/python3.8'
- 更新环境变量
$ source ~/.bashrc
- 再次激活 yolact++
conda activate yolact++
- 测试
python
import torch
torch.cuda.is_available()
torch.cuda.device_count()
torch.cuda.current_device()
Yolact++项目克隆安装
- 克隆和安装Yolact++
$ git clone https://github.com/dbolya/yolact.git
- 安装所需库
在yolact++环境中, 路径yolact下执行
$ pip install cython
$ pip install opencv-python pillow pycocotools matplotlib
- 安装DCN
$ git clone https://github.com/jinfagang/DCNv2_latest.git
- 在yolact++环境中, 路径DCNv2_latest下执行
$ cd DCNv2_latest
$ python setup.py build develop
$ python testcuda.py # run examples and gradient check on gpu
测试图片
下载测试图片到testfile
下,权重文件到weights下
使用yolact_plus_base模型
python eval.py --trained_model=weights/yolact_plus_base_54_800000.pth --score_threshold=0.15 --top_k=15 --image=testfiles/elephant.jpg:testfiles/elephant_seg.jpg
使用yolact_plus_resnet50模型
python eval.py --trained_model=weights/yolact_plus_resnet50_54_800000.pth --score_threshold=0.15 --top_k=15 --image=testfiles/elephant.jpg:testfiles/elephant_seg2.jpg
测试视频
python eval.py --trained_model=weights/yolact_plus_resnet50_54_800000.pth --score_threshold=0.15 --top_k=15 --video_multiframe=4 --video=testfiles/drive.mp4:testfiles/drive1.mp4