darknet優化經驗-AlexeyAB大神經驗


darknet優化經驗

主要來自於:AlexeyAB 版本darknet

1. AlexeyAB改進項

  • 提供window支持

  • 相較於原版pjreddie版本darknet提升了訓練速度

  • 添加了二值化網絡,XNOR(bit) ,速度快,准確率稍低https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov3-tiny_xnor.cfg

  • 提升7%通過將卷積層和BN層合並為一個(*_*)不太懂。

  • 多GPU訓練提升

  • 修補了[reorg]層

  • 添加了mAP, IOU,Precision-Recall計算

    darknet detector map...

  • 可以在訓練過程中畫loss圖像

  • 添加了根據自己數據集的anchor生成

  • 提升視頻檢測,網絡攝像頭,opencv相關問題

  • 提出了一個INT8的網絡,提升了檢測速度,但是准確率稍有下降

    https://github.com/AlexeyAB/yolo2_light

2. Linux下編譯選項

  • GPU=1 to build with CUDA to accelerate by using GPU (CUDA should be in /usr/local/cuda)
  • CUDNN=1 to build with cuDNN v5-v7 to accelerate training by using GPU (cuDNN should be in /usr/local/cudnn)
  • CUDNN_HALF=1 to build for Tensor Cores (on Titan V / Tesla V100 / DGX-2 and later) speedup Detection 3x, Training 2x
  • OPENCV=1 to build with OpenCV 3.x/2.4.x - allows to detect on video files and video streams from network cameras or web-cams
  • DEBUG=1 to bould debug version of Yolo
  • OPENMP=1 to build with OpenMP support to accelerate Yolo by using multi-core CPU
  • LIBSO=1 to build a library darknet.so and binary runable file uselib that uses this library. Or you can try to run so LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH ./uselib test.mp4 How to use this SO-library from your own code - you can look at C++ example: https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp or use in such a way: LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH ./uselib data/coco.names cfg/yolov3.cfg yolov3.weights test.mp4

3. 訓練經驗

  • 首先對數據集進行檢錯,使用提供的如下庫進行檢測:

https://github.com/AlexeyAB/Yolo_mark

  • 什么時候停止訓練

    • avg loss不再下降的時候

    • 通常每個類需要2000-4000次迭代訓練即可

    • 防止過擬合:需要在Early stopping point停止訓練

      使用以下命令:

      darknet.exe detector map...

      建議訓練的時候帶上-map,可以畫圖

      loss_chart_map_chart

4. 提升檢測效果

  • random=1可以設置適應多分辨率

  • 提升分辨率:416--> 608等必須是32倍數

  • 重新計算你的數據集的anchor:(注意設置的時候計算問題)

    darknet.exe detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height 416

  • 檢查數據集通過https://github.com/AlexeyAB/Yolo_mark

  • 數據集最好每個類有2000張圖片,至少需要迭代2000*類的個數

  • 數據集最好有沒有標注的對象,即負樣本,對應空的txt文件,最好有多少樣本就設計多少負樣本。

  • 對於一張圖有很多個樣本的情況,使用max=200屬性(yolo層或者region層)

  • for training for small objects - set layers = -1, 11 instead of https://github.com/AlexeyAB/darknet/blob/6390a5a2ab61a0bdf6f1a9a6b4a739c16b36e0d7/cfg/yolov3.cfg#L720 and set stride=4 instead of https://github.com/AlexeyAB/darknet/blob/6390a5a2ab61a0bdf6f1a9a6b4a739c16b36e0d7/cfg/yolov3.cfg#L717

  • 訓練數據需要滿足以下條件:

    • train_network_width * train_obj_width / train_image_width ~= detection_network_width * detection_obj_width / detection_image_width
    • train_network_height * train_obj_height / train_image_height ~= detection_network_height * detection_obj_height / detection_image_height
  • 為了加速訓練,可以做fine-tuning而不是從頭開始訓練,設置stopbackward=1在網絡的結束部分(以####作為分割)

  • 在訓練完以后,進行目標檢測的時候,可以提高網絡的分辨率,以便剛好檢測小目標。

    • 不需要重新訓練,需要使用原先低分辨率的權重,測用更高分辨率。
    • 為了得到更高的檢測效果,可以提升分辨率至608*608甚至832*832

5. 總結

為了小目標:

  • 提升分辨率
  • 在測試時候提升分辨率
  • 數據集添加跟正樣本數量一樣多的負樣本
  • 數據集每個類至少2000張,訓練迭代次數2000*classes個數
  • 設置自己數據集的anchor

6. AlexeyAB大神改進

  • web-cam版本:

./darknet detector demo ... -json_port 8070 -mjpeg_port 8090

  • 計算mAP, F1, IoU, Precision-Recall

./darknet detector map ...

  • 展示map-loss曲線(需要opencv)

./darknet detector train cfg/voc.data cfg/yolo.cfg -dont_show -mjpeg_port 8090 -map

  • 計算聚類產生的anchor

./darknet detector calc_anchors data/voc.data -num_of_clusters 12 -width 608 -height 608

  • 分離前部基礎網絡

./darknet partial cfg/darknet19_448.cfg darknet19_448.weights darknet19_448.conv.23 23

  • 測試opencv

./darknet imtest data/eagle.jpg

  • 閾值設置

-thresh 0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM