Darkflow: Different output from original code (darknet)

Created on 20 Feb 2017  路  9Comments  路  Source: thtrieu/darkflow

The result looks different from original code.
Anyone have idea how to fix this? I'm relatively new to darkflow.

darkflow

dog

darknet
predictions_dog_darknet

Most helpful comment

Finally, I find the problem after more than two days comparing Darknet and Darkflow.

A bug to be fixed @thtrieu

The author made a mistake in net/yolov2/test.py postprocess(), it says:
boxes = sorted(boxes, key = prob_compare)
It is designed to do NMS, but actually sorted() is to sort in ascending order!

It needs to be changed to:
boxes = sorted(boxes, key = prob_compare, reverse=True)

By doing so, the results are visually the same as Darknet version.

Other differences

  • The thresh to filter bboxes is different. This value is used in test.py. And it is defined in yolo.cfg: thresh=.3.
    But in original Darknet code, it is defined as:
    float thresh = find_float_arg(argc, argv, "-thresh", .24);, by default.

I guess the thresh in yolo.cfg is only used for training. And testing can use a different one. In Darknet code, thresh for testing is not from yolo.cfg file.

  • Important: imresize is very important. The Darknet 's imresize is different from others.
    I use its resized output as input to Tensorflow version, the result is the same as Darknet.
    But when I use OpenCV or scipy.misc.imresize() to resize, the results are different.
    I have no idea about the reason now.

  • Tiny difference in batch_norm. Darknet implement its own batch_norm. The core part is like:
    x[index] = (x[index] - mean[f])/(sqrt(variance[f]) + .000001f);
    And Darkflow used Tensorflow's batch_norm, which is like here.
    The difference lies in the way of handle epsilon, also the value is different.

P.S.
I am translating a light version of YOLO v2 to Tensorflow.
If anyone interests, I would like to put that on github.

All 9 comments

Same problem with yolo v2, used weight file: http://pjreddie.com/media/files/yolo.weights

Finally, I find the problem after more than two days comparing Darknet and Darkflow.

A bug to be fixed @thtrieu

The author made a mistake in net/yolov2/test.py postprocess(), it says:
boxes = sorted(boxes, key = prob_compare)
It is designed to do NMS, but actually sorted() is to sort in ascending order!

It needs to be changed to:
boxes = sorted(boxes, key = prob_compare, reverse=True)

By doing so, the results are visually the same as Darknet version.

Other differences

  • The thresh to filter bboxes is different. This value is used in test.py. And it is defined in yolo.cfg: thresh=.3.
    But in original Darknet code, it is defined as:
    float thresh = find_float_arg(argc, argv, "-thresh", .24);, by default.

I guess the thresh in yolo.cfg is only used for training. And testing can use a different one. In Darknet code, thresh for testing is not from yolo.cfg file.

  • Important: imresize is very important. The Darknet 's imresize is different from others.
    I use its resized output as input to Tensorflow version, the result is the same as Darknet.
    But when I use OpenCV or scipy.misc.imresize() to resize, the results are different.
    I have no idea about the reason now.

  • Tiny difference in batch_norm. Darknet implement its own batch_norm. The core part is like:
    x[index] = (x[index] - mean[f])/(sqrt(variance[f]) + .000001f);
    And Darkflow used Tensorflow's batch_norm, which is like here.
    The difference lies in the way of handle epsilon, also the value is different.

P.S.
I am translating a light version of YOLO v2 to Tensorflow.
If anyone interests, I would like to put that on github.

Wow thanks! I am fixing this ASAP.

@jiangsutx I am interested in your light version of YOLO V2

@jiangsutx Any evaluation on the influence of all those possible reasons?

@crazylyf The nms bug is the main problem. imresize() also influence the results. Other differences may not that important.

@jiangsutx Okay, thank you! Is there any experiment comparing the mAP on VOC or COCO dataset?

@crazylyf No. I am not an expert in Detection. I only want to use it in my other system. : )
Please let me know, if you have any updates. Thank you.

@jiangsutx I'm not familiar with tensorflow. Instead, I'm trying to find out the discrepancy between original darknet and pytorch version of yolo2 yolo2-pytorch.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LeeroyHannigan picture LeeroyHannigan  路  4Comments

1NNcoder picture 1NNcoder  路  3Comments

pribadihcr picture pribadihcr  路  5Comments

ShawnDing1994 picture ShawnDing1994  路  4Comments

ma3252788 picture ma3252788  路  3Comments