One.yolov5 configuration (GPU)
My computer configuration cuda 10.0
open CMD, enternvcc --version
1. Copy the configured cpu environment
Find the yolov5 folder in the envs folder of anaconda (cpu environment configured yesterday), copy and paste it into the envs folder and rename it to yolov5GPU
2. Download the GPU version of pytorch and pytorchvision
Open the pytorch official website to https://pytorch.org/get-started/locally/
view the version of the software package that needs to be installed
Open the https://download.pytorch.org/whl/torch_stable.html
required package for download (downloading from the pytorch official website is too slow)
because mine is cuda10.0, the package I installed is: torchvision-0.7.0+cu101-cp38-cp38-win_amd64.whl
andtorch-1.6.0+cu101-cp38-cp38-win_amd64.whl
After downloading, I found that only running yolov5s.pt model has no problem, but running yolov5x.pt will cause problems (see the description in the bug for specific problems), so I downloaded the
torchvision-0.8.2+cu101-cp38-cp38-win_amd64.whl
torchaudio-0.7.2-cp38-none-win_amd64.whl
torch-1.7.1+cu101-cp38-cp38-win_amd64.whl
torch and torchvision that were installed on the original cpu
pip uninstall torch
pip uninstall torchvision
Install a series of packages such as torch of the gpu version
pip install torchvision-0.8.2+cu101-cp38-cp38-win_amd64.whl
pip install torchaudio-0.7.2-cp38-none-win_amd64.whl
pip install torch-1.7.1+cu101-cp38-cp38-win_amd64.whl
(参考资料:1.https://www.bilibili.com/video/BV1FK411K78w?from=search&seid=354142551239432005
2.https://blog.csdn.net/water19111213/article/details/104352503
3.https://www.dtmao.cc/news_show_576859.shtml)
3. Test whether pytorch and torchvision are installed correctly
import torch
flag = torch.cuda.is_available()
print(flag)
ngpu= 1
# Decide which device we want to run on
```javascript
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
Two.yolov5 test
Download the yolov5 code and model (.pt file) on the official website https://github.com/ultralytics/yolov5
Open the yolov5 folder and enter
python detect.py --source 0 --weight E:\chengxu\yolov5\weights\yolov5s.pt
python detect.py --source 0 --weight E:\chengxu\yolov5\weights\yolov5x.pt
Three. bugs and solutions
1. pycocotools installation error
Solution: copy the cpu environment and download the gpu version of pytorch
2. pytorch and torchvision version report error
pkg_resources.VersionConflict:
(torchvision 0.7.0+cu101 (e:\anaconda\anaconda\envs\yolov5gpu\
lib\site-packages), Requirement.parse('torchvision>=0.8.1'))
Solution: Change the requirements.txt file in the yolov5 folder and comment out torch>=1.7.0 and torchvision>=0.8.1
#torch>=1.7.0
#torchvision>=0.8.1
3. The pytorch version is not compatible with yolov5
Problem Description:
(yolov5GPU) E:\chengxu\fadinglight-yolov5-master\yolov5>python detect.py --source 0 --weight E:\chengxu\fadinglight-yolov5-master\yolov5\weights\yolov5x.pt
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', project='runs/detect', save_conf=False, save_txt=False, source='0', update=False, view_img=False, weights=['E:\\chengxu\\fadinglight-yolov5-master\\yolov5\\weights\\yolov5x.pt'])
YOLOv5 torch 1.6.0+cu101 CUDA:0 (GeForce GTX 1650, 4096.0MB)
Traceback (most recent call last):
File "detect.py", line 175, in <module>
detect()
File "detect.py", line 33, in detect
model = attempt_load(weights, map_location=device) # load FP32 model
File "E:\chengxu\fadinglight-yolov5-master\yolov5\models\experimental.py", line 118, in attempt_load
ckpt = torch.load(w, map_location=map_location) # load
File "E:\anaconda\anaconda\envs\yolov5GPU\lib\site-packages\torch\serialization.py", line 584, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "E:\anaconda\anaconda\envs\yolov5GPU\lib\site-packages\torch\serialization.py", line 842, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'SiLU' on <module 'torch.nn.modules.activation' from 'E:\\anaconda\\anaconda\\envs\\yolov5GPU\\lib\\site-packages\\torch\\nn\\modules\\activation.py'>
Solution: Install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio===0.7.2
(the original is that torch==1.6.0+cu101 torchvision==0.7.0+cu101
torchaudio is not installed)
study-time
2021.3.12