tanluren / yolov3-channel-and-layer-pruning

yolov3 yolov4 channel and layer pruning, Knowledge Distillation 层剪枝,通道剪枝,知识蒸馏
Apache License 2.0
1.5k stars 446 forks source link

Is there a bug of the function letterbox in ./utils/datasets(line 617)? #83

Open Joker1994k opened 4 years ago

Joker1994k commented 4 years ago

https://github.com/tanluren/yolov3-channel-and-layer-pruning/blob/621e96f0d1059b30a854f6a9e1cf308d25051e6f/utils/datasets.py#L612

In "rect" mode, if the original img ratio of img.shape[0]/img.shape[1] is larger than new_shape[0] / new_shape[1], the parameter of r should be r = new_shape[0] / shape[0] rather than r = max(new_shape) / max(shape), which may lead to the dw or dh be negative numbers and raise errors in funciton cv2.copyMakeBorder in line 643. I think

    img_ratio = shape[0] / shape[1]
    if isinstance(new_shape, int):
        r = float(new_shape) / max(shape)  # ratio  = new / old
    else:
        new_ratio = new_shape[0] / new_shape[1]
        if img_ratio > new_ratio:
            r = new_shape[0] / shape[0]
        else:
            r = new_shape[1] / shape[1]    
        # else:
        #     r = max(new_shape) / max(shape)

is a more suitable solution. Am I right?

zbyuan commented 4 years ago

https://github.com/ultralytics/yolov3/blob/master/utils/datasets.py#L618 you can try