当前位置:网站首页>Training a yolov3 model for QR code region detection from scratch

Training a yolov3 model for QR code region detection from scratch

2020-11-10 15:18:53 yushulx

Bar code and two-dimensional code in the identification mainly includes positioning and decoding two steps . Look for the location of the code , In addition to using traditional image algorithms , You can also use deep learning . How efficient is deep learning , I did an experiment .

by QR QR code Training YOLOv3 Model

compile Darknet

download Darknet

git clone https://github.com/AlexeyAB/darknet --depth 1

My environment is Windows, So you need to install the following tools :

When the environment is set up ,CUDA It's the worst . Although we found nvcc Can work , but CMake Maybe we can't find . The problem here is CUDA Of Visual Studio The plug-in is not in the right place . The method that has been mentioned is CUDA To be in Visual Studio After the installation . But it's still possible that , The reason is that the system contains multiple versions of VC++ compiler . In my environment ,CUDA The plug-in is not installed correctly , So you have to manually get from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\visual_studio_integration\MSBuildExtensions copy to C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations

The next step is to run build.ps1 compile Darknet. If PowerShell The security policy of is the default , Need to use Administrator rights Start and modify permissions :

Set-ExecutionPolicy Bypass
build.ps1

After compiling, run the command to see if GPU edition :

darknet.exe detector test
 CUDA-version: 10010 (10010), cuDNN: 7.6.5, CUDNN_HALF=1, GPU count: 1
 CUDNN_HALF=1

Prepare the data

Find some on the Internet QR Pictures of the , I have 250 Zhang . And then use labeImg Mark each picture with QR Location :

 Insert picture description here

I am here LabelImg Code recognition is added to it , In the box selection, the corresponding code type will be automatically obtained . Here's my dataset .

 Insert picture description here

stay Darknet Of data Create under directory qrcode and qrcode-valid Catalog . Copy these pictures and tagging information into two directories , One for training , One for verification .

Create the corresponding configuration file :qrcode.data, qrcode.txt, qrcode-valid.txt, qrcode.names, qrcode-yolo3v.cfg and qrcode-yolov3-tiny.cfg

  • qrcode.data:

    	classes = 1
    	train = data/qrcode.txt
    	valid = data/qrcode-valid.txt
    	names = data/qrcode.names
    	backup = backup/
    
  • qrcode.txt and qrcode-valid.txt Contains the file names in two directories . These two documents can be passed through https://github.com/theAIGuysCode/YoloGenerateTrainingFile/blob/master/generate_train.py This Python Scripts are generated automatically

  • qrcode-yolo3v.cfg be based on yolo3v.cfg

  • qrcode-yolov3-tiny.cfg be based on yolo3v-tiny.cfg

Because you only need to train one class ,cfg The document is modified as follows :

classes=1
filters=18
max_batches = 4000
steps=3200,3600

Please refer to the document for specific meaning :https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

Training models

download darknet53.conv.74 Start training model :

darknet.exe detector train data/qrcode.data cfg/qrcode-yolov3.cfg darknet53.conv.74

 Insert picture description here

darknet.exe detector train data/qrcode.data cfg/qrcode-yolov3-tiny.cfg darknet53.conv.74

 Insert picture description here

QR Area detection performance test

My hardware configuration

GPU: NVIDIA RTX2060
CPU: Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz, 3201 Mhz, 4 Core(s), 4 Logical Processor(s)

The test image

 Insert picture description here

YOLOv3-tiny test

darknet.exe detector test qrcode.data qrcode-yolov3-tiny.cfg qrcode-yolov3-tiny_last.weights 20201105151910.jpg

Done! Loaded 24 layers from weights-file
 Detection layer: 16 - type = 28
 Detection layer: 23 - type = 28
20201105151910.jpg: Predicted in 3.717000 milli-seconds.
QR_CODE: 97%

 Insert picture description here

YOLOv3 test

darknet.exe detector test qrcode.data qrcode-yolov3.cfg qrcode-yolov3_last.weights 20201105151910.jpg 

Done! Loaded 107 layers from weights-file
 Detection layer: 82 - type = 28
 Detection layer: 94 - type = 28
 Detection layer: 106 - type = 28
20201105151910.jpg: Predicted in 31.717000 milli-seconds.
QR_CODE: 100%

 Insert picture description here

Through comparison, we found that YOLOv3 Than YOLOv3-tiny It takes a lot of time . The real-time requirement of scanning code is high ,YOLOv3-tiny More suitable for QR.

Test model download

版权声明
本文为[yushulx]所创,转载请带上原文链接,感谢