yolo V2
YOLO: Real-Time Object Detection
只看一次 (YOLO)是一個實時對象檢測系統(tǒng)。在 Titan X 上處理速度可以達到 40-90 FPS ,在? VOC 2007 上mAP(平均準(zhǔn)確率)為78.6% ,在COCO test-dev上平均準(zhǔn)確率為48.1%。
| Old YOLO | VOC 2007+2012 | 2007 | 63.4 | 40.19 Bn | 45 | link | |
| SSD300 | VOC 2007+2012 | 2007 | 74.3 | - | 46 | link | |
| SSD500 | VOC 2007+2012 | 2007 | 76.8 | - | 19 | link | |
| YOLOv2 | VOC 2007+2012 | 2007 | 76.8 | 34.90 Bn | 67 | cfg | weights |
| YOLOv2 544x544 | VOC 2007+2012 | 2007 | 78.6 | 59.68 Bn | 40 | cfg | weights |
| Tiny YOLO | VOC 2007+2012 | 2007 | 57.1 | 6.97 Bn | 207 | cfg | weights |
| | |||||||
| SSD300 | COCO trainval | test-dev | 41.2 | - | 46 | link | |
| SSD500 | COCO trainval | test-dev | 46.5 | - | 19 | link | |
| YOLOv2 608x608 | COCO trainval | test-dev | 48.1 | 62.94 Bn | 40 | cfg | weights |
| Tiny YOLO | COCO trainval | - | - | 7.07 Bn | 200 | cfg | weights |
YOLO是如何工作的
(Prior detection systems repurpose classifiers or localizers to perform detection)以前的檢測系統(tǒng)重新賦予分類或定位新的意義進行檢測。它們將模型應(yīng)用于一個圖像的多個位置和不同的尺度。圖像得分高的區(qū)域被認(rèn)為是檢測有效區(qū)域。
我們使用完全不同的方法。我們把一個單一的神經(jīng)網(wǎng)絡(luò)應(yīng)用于全像。該網(wǎng)絡(luò)將圖像分割成區(qū)域,并預(yù)測包圍盒和每個區(qū)域的概率。這些包圍盒由預(yù)測概率加權(quán)。
我們的模型和基于分類器的系統(tǒng)比有很多優(yōu)點。它著眼于整個圖像所以它的預(yù)測是結(jié)合圖像整個上下文內(nèi)容的。預(yù)測使用的一個單一的網(wǎng)絡(luò),不像R-CNN需要上千個網(wǎng)絡(luò)。這使得它非常快,比R-CNN快1000倍,比Fast R-CNN快100X以上。更多的信息,請參見我們的論文(paper)。
版本2的創(chuàng)新點是什么?
YOLOv2使用了一些技巧來提高訓(xùn)練和增加性能。像overfeat和SSD一樣,我們使用了一個完全卷積模型,但我們還是在整個圖像上訓(xùn)練,不難否定。像Faster R-CNN一樣我們調(diào)整了包圍盒的priors來代替完全的預(yù)測寬度和高度。但是,我們?nèi)匀恢苯宇A(yù)測x和y坐標(biāo)。詳細(xì)的細(xì)節(jié)請參見論文(paper)!
使用預(yù)先訓(xùn)練好的模型進行檢測(Detection Using A Pre-Trained Model)
這邊博文將會指導(dǎo)你使用預(yù)先訓(xùn)練好的YOLO模型進行檢測. 如果你還沒喲安裝 Darknet, 請先進行 安裝. 或者直接運行下面的命令:
git clone https://github.com/pjreddie/darknet cd darknet make簡單吧!
YOLO 的配置文件目錄為 cfg/ 子目錄. 下載預(yù)先訓(xùn)練好的權(quán)因子文件 here (258 MB). 或直接運行如下命令:
wget https://pjreddie.com/media/files/yolo.weights然后進行檢測!
./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg你將會看到類似下面的輸出:
layer filters size input output0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 321 max 2 x 2 / 2 416 x 416 x 32 -> 208 x 208 x 32.......29 conv 425 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 42530 detection Loading weights from yolo.weights...Done! data/dog.jpg: Predicted in 0.016287 seconds. car: 54% bicycle: 51% dog: 56%Darknet 會輸出檢測到的對象, 對象的可信度,以及檢測的時間消耗. 便宜Darknet 的時候沒有使用OpenCV 所以不能只能圖片呈現(xiàn)檢測結(jié)果. 但是可以早保存的文件predictions.png中查看.? 因為我們使用CPU版 Darknet 所以每幅圖像消耗大約 6-12. 如果使用GPU版本的將會比較快.
我已經(jīng)存儲了一些示例測試圖片,嘗試 data/eagle.jpg, data/dog.jpg, data/person.jpg, or data/horses.jpg !
檢測命令是命令的更一般版本的簡寫。它相當(dāng)于命令::
./darknet detector test cfg/coco.data cfg/yolo.cfg yolo.weights data/dog.jpg除了上面那樣,也可以通過攝像頭做實時檢測(which you will see later on).
多圖像(Multiple Images)
與其在命令行上提供圖像,還可以將其留空以嘗試多個圖像。相反,當(dāng)配置和權(quán)重完成加載時,您將看到一個提示符:
./darknet detect cfg/yolo.cfg yolo.weights layer filters size input output0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 321 max 2 x 2 / 2 416 x 416 x 32 -> 208 x 208 x 32.......29 conv 425 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 42530 detection Loading weights from yolo.weights ...Done! Enter Image Path:輸入一個圖像的路徑,如 data/horses.jpg 獲取圖像預(yù)測的包圍盒
一旦檢測完成,它會提示你輸入更多的路徑嘗試不同的圖像。使用Ctrl-C退出程序.
改變檢測的閾值(Changing The Detection Threshold)
默認(rèn), YOLO 只能顯示可信度大于等于.25的檢測對象. 這個可以通過傳遞參數(shù) -thresh <val> 改變.例如,顯示所有的檢測可以設(shè)置 threshold 為0:
./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg -thresh 0將會產(chǎn)生如下效果
所以,顯然不是超級有用,但你可以將它設(shè)置為不同的值來控制得到的閾值模型。
Tiny YOLO
Tiny YOLO 基于 Darknet reference network 并且非常快,但是精確度較正常的 YOLO 模型低. 使用基于VOC訓(xùn)練的模型:
wget https://pjreddie.com/media/files/tiny-yolo-voc.weights ./darknet detector test cfg/voc.data cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/dog.jpg不精確,但是確實快. 在GPU上>200 FPS.
使用攝像頭進行實時檢測(Real-Time Detection on a Webcam)
為了使用攝像頭,你需要在編譯 Darknet 的時候使用 CUDA 和 OpenCV. 然后運行下面的命令:
./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weightsYOLO將會像是當(dāng)前的 FPS和預(yù)測的分類 并在圖像上用包圍框畫出來.
運行的時候需要有攝像頭連接到計算機上,如果你有多個攝像頭你需要通錯參數(shù)選擇一個? -c <num>? (OpenCV uses webcam0 by default).
也可以使用視頻文件:
./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights <video file>That's how we made the YouTube video above.
在VOC上訓(xùn)練YOLO模型(Training YOLO on VOC)
You can train YOLO from scratch if you want to play with different training regimes, hyper-parameters, or datasets. Here's how to get it working on the Pascal VOC dataset.
Get The Pascal VOC Data
訓(xùn)練 YOLO 需要 2007 到2012年的VOC數(shù)據(jù). 也可以點這里下載here. 可以直接運行下面的命令:
curl -O https://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar curl -O https://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar curl -O https://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar tar xf VOCtrainval_11-May-2012.tar tar xf VOCtrainval_06-Nov-2007.tar tar xf VOCtest_06-Nov-2007.tarThere will now be a VOCdevkit/ subdirectory with all the VOC training data in it.
Generate Labels for VOC
Now we need to generate the label files that Darknet uses. Darknet wants a .txt file for each image with a line for each ground truth object in the image that looks like:
<object-class> <x> <y> <width> <height>Where x, y, width, and height are relative to the image's width and height. To generate these file we will run thevoc_label.py script in Darknet's scripts/ directory. Let's just download it again because we are lazy.
curl -O https://pjreddie.com/media/files/voc_label.py python voc_label.pyAfter a few minutes, this script will generate all of the requisite files. Mostly it generates a lot of label files inVOCdevkit/VOC2007/labels/ and VOCdevkit/VOC2012/labels/. In your directory you should see:
ls 2007_test.txt VOCdevkit 2007_train.txt voc_label.py 2007_val.txt VOCtest_06-Nov-2007.tar 2012_train.txt VOCtrainval_06-Nov-2007.tar 2012_val.txt VOCtrainval_11-May-2012.tarThe text files like 2007_train.txt list the image files for that year and image set. Darknet needs one text file with all of the images you want to train on. In this example, let's train with everything except the 2007 test set so that we can test our model. Run:
cat 2007_train.txt 2007_val.txt 2012_*.txt > train.txtNow we have all the 2007 trainval and the 2012 trainval set in one big list. That's all we have to do for data setup!
Modify Cfg for Pascal Data
Now go to your Darknet directory. We have to change the cfg/voc.data config file to point to your data:
1 classes= 202 train = <path-to-voc>/train.txt3 valid = <path-to-voc>2007_test.txt4 names = data/voc.names5 backup = backupYou should replace <path-to-voc> with the directory where you put the VOC data.
Download Pretrained Convolutional Weights
For training we use convolutional weights that are pre-trained on Imagenet. We use weights from theExtraction model. You can just download the weights for the convolutional layershere (76 MB).
curl -O https://pjreddie.com/media/files/darknet19_448.conv.23If you want to generate the pre-trained weights yourself, download the pretrainedDarknet19 448x448 model and run the following command:
./darknet partial cfg/darknet19_448.cfg darknet19_448.weights darknet19_448.conv.23 23But if you just download the weights file it's way easier.
Train The Model
Now we can train! Run the command:
./darknet detector train cfg/voc.data cfg/yolo-voc.cfg darknet19_448.conv.23Training YOLO on COCO
You can train YOLO from scratch if you want to play with different training regimes, hyper-parameters, or datasets. Here's how to get it working on theCOCO dataset.
Get The COCO Data
To train YOLO you will need all of the COCO data and labels. The script scripts/get_coco_dataset.sh will do this for you. Figure out where you want to put the COCO data and download it, for example:
cp scripts/get_coco_dataset.sh data cd data bash get_coco_dataset.shNow you should have all the data and the labels generated for Darknet.
Modify cfg for COCO
Now go to your Darknet directory. We have to change the cfg/coco.data config file to point to your data:
1 classes= 802 train = <path-to-coco>/trainvalno5k.txt3 valid = <path-to-coco>/5k.txt4 names = data/coco.names5 backup = backupYou should replace <path-to-coco> with the directory where you put the COCO data.
You should also modify your model cfg for training instead of testing. cfg/yolo.cfg should look like this:
[net] # Testing # batch=1 # subdivisions=1 # Training batch=64 subdivisions=8 ....Train The Model
Now we can train! Run the command:
./darknet detector train cfg/coco.data cfg/yolo.cfg darknet19_448.conv.23If you want to use multiple gpus run:
./darknet detector train cfg/coco.data cfg/yolo.cfg darknet19_448.conv.23 -gpus 0,1,2,3If you want to stop and restart training from a checkpoint:
./darknet detector train cfg/coco.data cfg/yolo.cfg backup/yolo.backup -gpus 0,1,2,3What Happened to the Old YOLO Site?
If you are using YOLO version 1 you can still find the site here: https://pjreddie.com/darknet/yolov1/
Cite
If you use YOLOv2 in your work please cite our paper!
@article{redmon2016yolo9000,title={YOLO9000: Better, Faster, Stronger},author={Redmon, Joseph and Farhadi, Ali},journal={arXiv preprint arXiv:1612.08242},year={2016} }總結(jié)
- 上一篇: Python中的sorted函数以及op
- 下一篇: MAP(Mean Average Pre