Detailed explanation of the installation steps of yolov4's Pytorch (cpu version), you can learn it with your hands

my environment

win10+anaconda (created python=3.6 version)+yolov4+Pytorch (cpu version)

1. Prepare documents

  1. pytorch-YOLOv4 code download https://github.com/Tianxiaomo/pytorch-YOLOv4
    The above one has been updated by others, there may be errors in this article, because I downloaded the version before, you can download this, follow the steps in the article It should be fine. (Uploaded on September 13)
    Link: https://pan.baidu.com/s/1AmCL25n6yKpABF1j7w1CFg
    Extraction code: w448
  2. Weights (weights) model download
    Google cloud disk https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT
    GitHub download https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
    put the above After the code is downloaded, unzip it, create a weight folder in the unzipped directory, and put the above weight file in the weight folder. After sorting, the picture is as follows: insert image description here
    all the sub-files are ready

2. Create the environment

  1. Anaconda creates a virtual environment of python=3.6
    Enter cmd, command conda create -n yolov4 (this is the name) python=3.6
conda create -n yolov4 python=3.6

activate the environment

activate yolov3-pytorch

You also need to install dependencies, you can go to the official website to choose according to your needs, https://pytorch.org/

My command is as follows

conda install pytorch torchvision cpuonly -c pytorch

I only need to install this one. All the dependent packages are as follows, and I don't understand the meaning of each one.

(ceshi) C:\Users\Administrator\Desktop\YOLOv4\pytorch-YOLOv4-master\pytorch-YOLOv4-master>pip list
Package      Version
------------ -------------------
certifi      2020.4.5.1
mkl-fft      1.0.15
mkl-random   1.1.0
mkl-service  2.3.0
numpy        1.18.1
olefile      0.46
Pillow       7.1.2
pip          20.0.2
setuptools   46.1.3.post20200330
six          1.14.0
torch        1.5.0
torchvision  0.6.0
wheel        0.34.2
wincertstore 0.2

At this point, the files are ready, the environment is set up, and the next step is testing.

3. Test

Open cmd, activate the built environment, enter the file directory you decompressed, and then use the following command to ensure that each file is in the corresponding folder (yolov4.cfg is in the cfg folder, yolov4.weights is in the weight file folder, dog.jpg is in the data folder)

python demo.py cfg/yolov4.cfg weight/yolov4.weights data/dog.jpg

Part of the code after running is as follows:

  149 conv    255  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 255
  150 detection
  151 route  147
  152 conv    512  3 x 3 / 2    38 x  38 x 256   ->    19 x  19 x 512
  153 route  152 116
  154 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512
  155 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024
  156 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512
  157 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024
  158 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512
  159 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024
  160 conv    255  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 255
  161 detection
Loading weights from weight/yolov4.weights... Done!
data/dog.jpg: Predicted in 5.850648 seconds.
truck: 0.970982
dog: 0.999997
bicycle: 1.000000
save plot results to predictions.jpg

There is an additional picture file under the folder, we can rename it predictions_yolov4.jpg, otherwise, if you test another picture, this one will be overwritten. Then you can test another picture, the command is as follows:

python demo.py cfg/yolov4.cfg weight/yolov4.weights data/giraffe.jpg

In this way, the test of the two pictures is completed. 4
the second
insert picture sketch here
If you have yolov3.weights, https://pjreddie.com/media/files/yolov3.weights
also put this weight under the weight folder, you can test the effect of yolov3. The code needs to be modified, just change yolov4 to yolov3, the command is as follows:

python demo.py cfg/yolov3.cfg weight/yolov3.weights data/dog.jpg

The picture is below, this is not as good as yolov4, it should have something to do with my program not being modified! !insert image description here
insert image description here

4. camera.py and models.py

If you want to use comera.py, you need to add a dependency package opencv-python, the command is as follows:

pip install opencv-python

Then just run camera.py directly, which is to call the camera of the computer, frame the image and mark it. The command is:

python camera.py

The image is:
insert image description here

The computer camera and accuracy are worrying.

Okay, that’s all for writing, I feel like I’m a fool, I’m doing it step by step, and I can learn to use it if I have a hand, have you learned to use it? . . . . Button 6 for those who have learned to useless, and buttonholes for those who have not learned to useless.
As for models.py, I haven't read it much yet. The point is that I don't understand it too much, so I won't write it for now.

Reference: https://blog.csdn.net/AliceZyxw/article/details/105307498

https://blog.csdn.net/weixin_45829462/article/details/104705937

Guess you like

Origin blog.csdn.net/qq_36693723/article/details/105907174