PyTorch_YOLOv4
PyTorch_YOLOv4 copied to clipboard
mismatch results compared with official YOLOv4
I tested yolov4.cfg and yolov4.weights downloaded from AB, and test its mAP results with
CUDA_VISIBLE_DEVICES='5' python test.py --cfg ./cfg/yolov4.cfg --weights ./weights/yolov4.weights --img-size 320 --save-json --data ./data/coco.yaml
(cfg file in your repo, but weights file from https://github.com/AlexeyAB/darknet)
but only got 0.45 [email protected], how is that? Have I missed some important things? or use the weights and cfg wrongly? Thanks for your replying.
COCO results for img-size=320
and this is for img-size=416
weights file are training with different decoder in this and ab repo. this repo use new_coord=1 while ab use new_coord=0. if you want to inference weights from ab repo, you could try u3_preview branch.
Hi, I test weights from DarkNet project, and still a small amount margin between yours (u3_preview) and https://github.com/AlexeyAB/darknet.
Details:
test2017:
weights from AB, tested with u3_preview, image resolution 416x416
weights from AB, tested with u3_preview, image resolution 512x512
compared with original YOLOv4 in 416x416, mAP & [email protected] are 41.2 (+1.6) & 61.8 (+2.6) compared with original YOLOv4 in 512x512, mAP & [email protected] are 43.0 (+1.3) & 64.9 (+1.9)
The gaps are much smaller than that in master branch, but still non-negligible
scale_x_y implementation is needed here.
thx for your answer, but i wonder what is the implementation of scale_x_y, I'm not that familiar with YOLOv4 🙏
https://github.com/AlexeyAB/darknet/issues/3293
io = p.clone() # inference output
# io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy
io[..., :2] = torch.sigmoid(io[..., :2]) * 1.2 - 0.5 * (1.2 - 1)
io[..., 2:4] = torch.exp(io[..., 2:4]) * self.anchor_wh # wh yolo method
io[..., :4] *= self.stride
torch.sigmoid_(io[..., 4:])
return io.view(bs, -1, self.no), p # view [1, 3, 13, 13, 85] as [1, 507, 85]
我这样修改的,但是精度变成0了
xy 少了 + self.grid
io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy
io[..., :2] = torch.sigmoid(io[..., :2]) * 1.2 - 0.5 * (1.2 - 1)
io[..., :2] = torch.sigmoid(io[..., :2]) * 1.2 - 0.5 * (1.2 - 1)
io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy
应该是哪个呢,我感到比较疑惑
後者, 沒有加 grid, 就是所有 box 都在圖片左上角的意思.
另外要注意, original yolov4 三個預測層的參數不一樣.
io = p.clone() # inference output
io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy
io[..., 2:4] = torch.exp(io[..., 2:4]) * self.anchor_wh # wh yolo method
io[..., :4] *= self.stride
torch.sigmoid_(io[..., 4:])
我使用原版yolov4-mish在416能在val下获得0.471,但在test下只有0.399,这低于0.415
io = p.clone() # inference output
io[..., :2] = torch.sigmoid(io[..., :2]) * 1.2 - 0.5 * (1.2 - 1)
io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy
io[..., 2:4] = torch.exp(io[..., 2:4]) * self.anchor_wh # wh yolo method
io[..., :4] *= self.stride
torch.sigmoid_(io[..., 4:])
我使用这个只得到val上的0.290
io = p.clone() # inference output
io[..., :2] = torch.sigmoid(io[..., :2]) * 1.2 - 0.5 * (1.2 - 1)
io[..., :2] = io[..., :2] + self.grid # xy
io[..., 2:4] = torch.exp(io[..., 2:4]) * self.anchor_wh # wh yolo method
io[..., :4] *= self.stride
torch.sigmoid_(io[..., 4:])
我得到了0.475的val精度,我发现我多了一个sigmoid
三个预测层参数不一样是什么意思,我应该如何修改,因为我想对齐AB的性能
三層的scale_x_y分別是1.2, 1.1, 和 1.05.
谢谢你的提醒,这与cfg文件是一致的,这解决了我的问题
再请问一下conf和iou的设置需要修改吗,我为YOLOLayer增加了scale_x_y参数读取,使其能正确读入各层对应的scale_x_y,但是yolov4-mish在test下为0.404这低于0.415