pytorch-YOLOv4 icon indicating copy to clipboard operation
pytorch-YOLOv4 copied to clipboard

very slow when evaluate on COCO dataset, about half hour per image!

Open liukaigua opened this issue 4 years ago • 4 comments

this is the command, and the weight is default "yolov4.weight".

python evaluate_on_coco.py -dir COCO_dataset/val2017 -gta COCO_dataset/instances_val2017.json -c cfg/yolov4.cfg -g 1

I made slight changes on evaluate_on_coco.py, otherwise it would report errors.

 # do one forward pass first to circumvent cold start
    throwaway_image = Image.open('data/dog.jpg').convert('RGB').resize((model.width, model.height))
    #do_detect(model, throwaway_image, 0.5, 80, 0.4, use_cuda)
    **do_detect(model, throwaway_image, 0.5, 0.4, use_cuda) # the first change**
    boxes_json = []

    for i, image_annotation in enumerate(images):
        logging.info("currently on image: {}/{}".format(i + 1, len(images)))
        image_file_name = image_annotation["file_name"]
        image_id = image_annotation["id"]
        image_height = image_annotation["height"]
        image_width = image_annotation["width"]

        # open and resize each image first
        img = Image.open(os.path.join(cfg.dataset_dir, image_file_name)).convert('RGB')
        sized = img.resize((model.width, model.height))

        if use_cuda:
            model.cuda()

        start = time.time()
        #boxes = do_detect(model, sized, 0.0, 80, 0.4, use_cuda)
        **boxes = do_detect(model, sized, 0.0, 0.4, use_cuda)  # second change**
        finish = time.time()
        if type(boxes) == list:
            #for box in boxes:
            **for box in boxes[0]:  # third change**
                #print(np.array(boxes).shape) # (1,6536,7)
                box_json = {}
                category_id = box[-1]

but the speed is really slow, does anyone have some idea?

liukaigua avatar Dec 07 '20 12:12 liukaigua

-----------------------------------
           Preprocess : 0.003181
      Model Inference : 0.208495
-----------------------------------
-----------------------------------
       max and argmax : 0.006351
                  nms : 0.001029
Post processing total : 0.007380
-----------------------------------
2020-12-07 03:55:04,632 evaluate_on_coco.py[line:180] INFO: currently on image: 1/5000
-----------------------------------
           Preprocess : 0.002940
      Model Inference : 0.046921
-----------------------------------
-----------------------------------
       max and argmax : 0.004659
                  nms : 0.319768
Post processing total : 0.324427
-----------------------------------
2020-12-07 04:04:16,979 evaluate_on_coco.py[line:180] INFO: currently on image: 2/5000
-----------------------------------
           Preprocess : 0.012776
      Model Inference : 0.046139
-----------------------------------
-----------------------------------
       max and argmax : 0.005223
                  nms : 0.308276
Post processing total : 0.313498
-----------------------------------
2020-12-07 04:37:14,106 evaluate_on_coco.py[line:180] INFO: currently on image: 3/5000
-----------------------------------
           Preprocess : 0.017259
      Model Inference : 0.054760
-----------------------------------
-----------------------------------
       max and argmax : 0.006820
                  nms : 0.442842
Post processing total : 0.449662
-----------------------------------

liukaigua avatar Dec 07 '20 12:12 liukaigua

I have the same problem.(俺也一样)

xiaohuan1208 avatar Dec 12 '20 02:12 xiaohuan1208

Then I chage the conf_thresh from 0.0 to 0.5.

xiaohuan1208 avatar Dec 12 '20 04:12 xiaohuan1208

I have the same problem.(俺也一样)

你测出来精度是多杀

GuoQuanhao avatar Sep 18 '21 07:09 GuoQuanhao