Python影像辨識筆記(二十二):Scaled-YOLOv4: Scaling Cross Stage Partial Network相關連結與介紹

Yanwei Liu
10 min readNov 18, 2020

更新內容

Q: what is OSAnet?
the proposed COSA can get a higher AP. Therefore, we finally chose COSA-2x2x which received the best speed/accuracy trade-off in our experiment as the YOLOv4-tiny architecture.
A: OSA module in VoVNet to build OSANet.
Q: YOLOv4-tiny 和YOLOv4-tiny-3l的差別?
A: there are 2 yolo layers in yolov4-tiny, while 3l has 3.
Q: YOLOv4-tiny訓練COCO2017出來的AP結果比darknet版本低?
A:
[1]訓練yolov4-tiny的程式可以參考這裡
[2]在這行後面暫時加上 balance = [0.4, 1.0] if np == 2 else balance
2020/12/29更新:[3]使用這個方式讓程式碼支援RouteGroup功能
Q: tiny yolo使用darknet進行from scratch的訓練時,max_batches該如何設定?
A:
tiny models train from scratch 的話 max_batches 建議設成 2000200、training loss只是個相對值,不管數值多少,都有可能是正常的。(我自己使用經驗是tiny版本訓練出來的loss會高於一般yolo版本)
Q: 如何使用TensorRT?
A:
python3 export_onnx.py --cfg_file cfg/yolov4-csp.cfg --weights_file yolov4-csp.weights --output_file yolov4-csp.onnx --sigmoid
./Yolov4_trt ../config-yolov4-csp.yaml ../samples/Q: 訓練後的label.png簡介
A: label.png 請教
Q: original.pt與original_strip.pt的差別
A: strip會把optimizer宰掉, 還有一些資訊清掉, 可以當作pretrained weights.
Q: 原始yolo4-tiny.cfg和ScaledYOLOv4中的yolov4-tiny.cfg之差別
A:
the only difference is that yolov4-tiny in scaled-yolov4 is trained from scratch.(max batched 2000200比上500200)
Q: 如何添加自定義Layer?
A: 參考這裡
Q: yolov4-csp該切開到第幾層?
A: 第142層(yolov4-csp.conv.142)

YOLOv4系列模型效能比較

論文連結

GitHub Repo

新增的功能

對比舊版的PyTorch_YOLOv4,這個版本的程式碼支援多GPU訓練、高Batch size訓練(batch = 64,每個epochs約15分鐘)、resume training、支援YOLOv4-tiny(須自己修改程式碼)、支援pre-trained weight訓練。

資料集準備

請使用COCO2017作為訓練集、驗證集、測試集,若用COCO2014的dataset,會出現這個錯誤可使用get_coco2017.sh這個script來進行dataset下載filename="coco2017labels.zip"
fileid="1cXZR_ckHki6nddOmcysCuuJFM--T-Q6L"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" >/dev/nullcurl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=$(awk '/download/ {print $NF}' ./cookie)&id=${fileid}" -o ${filename}rm ./cookieunzip -q ${filename} # for coco.zip
rm ${filename}
cd coco/imagesf="train2017.zip" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $ff="val2017.zip" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $f

使用方法

yolov4-csp branch在aiForge的主機為例:

git clone https://github.com/JunnYu/mish-cuda
cd mish-cuda
python setup.py install
cd ..wget https://github.com/WongKinYiu/ScaledYOLOv4/archive/yolov4-csp.zipunzip yolov4-csp.zip && rm yolov4-csp.zipcd ScaledYOLOv4-yolov4-cspmkdir weights && cd weightswget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1NQwz47cW0NUgy7L3_xOKaNEfLoQuq3EL' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1NQwz47cW0NUgy7L3_xOKaNEfLoQuq3EL" -O yolov4-csp.weights && rm -rf /tmp/cookies.txtcd ..# Testing
python test.py --img 640 --conf 0.001 --batch 8 --device 0 --data coco.yaml --cfg models/yolov4-csp.cfg --weights weights/yolov4-csp.weights
# Multi GPU Training
python -m torch.distributed.launch --nproc_per_node 4 train.py --device 0,1,2,3 --batch-size 64 --data coco.yaml --cfg yolov4-csp.cfg --weights '' --name yolov4-csp --sync-bn

yolov4-csp branch在TWCC國網中心的主機為例:

pip install git+https://github.com/thomasbrandon/mish-cuda/pip install matplotlibwget https://github.com/WongKinYiu/ScaledYOLOv4/archive/yolov4-csp.zipunzip yolov4-csp.zip && rm yolov4-csp.zipcd yolov4-cspmkdir weights && cd weightswget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1NQwz47cW0NUgy7L3_xOKaNEfLoQuq3EL' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1NQwz47cW0NUgy7L3_xOKaNEfLoQuq3EL" -O yolov4-csp.weights  && rm -rf /tmp/cookies.txtcd ..# Testing
python test.py --img 640 --conf 0.001 --batch 8 --device 0 --data coco.yaml --cfg models/yolov4-csp.cfg --weights weights/yolov4-csp.weights
# Multi GPU Training
python -m torch.distributed.launch --nproc_per_node 4 train.py --device 0,1,2,3 --batch-size 64 --data coco.yaml --cfg yolov4-csp.cfg --weights '' --name yolov4-csp --sync-bn

其他介紹

--

--