Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mismatch results compared with official YOLOv4 #199

Open
cjnjuwhy opened this issue Dec 7, 2020 · 15 comments
Open

mismatch results compared with official YOLOv4 #199

cjnjuwhy opened this issue Dec 7, 2020 · 15 comments

Comments

@cjnjuwhy
Copy link

cjnjuwhy commented Dec 7, 2020

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
7131607357279_ pic_hd

and this is for img-size=416
image

@WongKinYiu
Copy link
Owner

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.

@cjnjuwhy
Copy link
Author

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
138491607954857_ pic_hd
weights from AB, tested with u3_preview, image resolution 512x512
137681607949089_ pic

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

@WongKinYiu
Copy link
Owner

scale_x_y implementation is needed here.

@cjnjuwhy
Copy link
Author

thx for your answer, but i wonder what is the implementation of scale_x_y, I'm not that familiar with YOLOv4
🙏

@GuoQuanhao
Copy link

scale_x_y implementation is needed here.

Hi, how to realize scale_x_y

@WongKinYiu
Copy link
Owner

AlexeyAB/darknet#3293

@GuoQuanhao
Copy link

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了

@WongKinYiu
Copy link
Owner

xy 少了 + self.grid

@GuoQuanhao
Copy link

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

应该是哪个呢,我感到比较疑惑

@WongKinYiu
Copy link
Owner

後者, 沒有加 grid, 就是所有 box 都在圖片左上角的意思.

@WongKinYiu
Copy link
Owner

另外要注意, original yolov4 三個預測層的參數不一樣.

@GuoQuanhao
Copy link

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的性能

@WongKinYiu
Copy link
Owner

三層的scale_x_y分別是1.2, 1.1, 和 1.05.

@GuoQuanhao
Copy link

GuoQuanhao commented Sep 24, 2021

谢谢你的提醒,这与cfg文件是一致的,这解决了我的问题

@GuoQuanhao
Copy link

再请问一下conf和iou的设置需要修改吗,我为YOLOLayer增加了scale_x_y参数读取,使其能正确读入各层对应的scale_x_y,但是yolov4-mish在test下为0.404这低于0.415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants