Megvii-BaseDetection / YOLOX

YOLOX is a high-performance anchor-free YOLO, exceeding yolov3~v5 with MegEngine, ONNX, TensorRT, ncnn, and OpenVINO supported. Documentation: https://yolox.readthedocs.io/
Apache License 2.0
9.47k stars 2.21k forks source link

tiny model is faster than nano model on Jetson Xaiver NX #1556

Open ryotaro137 opened 2 years ago

ryotaro137 commented 2 years ago

I have measured detection speed on Jetson Xaiver NX.

The results is below (using fp16) nano : 0.0721[s] tiny : 0.0662[s]

Would you tell me the cause of the result? Thank you in advance.

FateScript commented 2 years ago

It's quite strange for me. Could you plz show me the profile result in detail?

ryotaro137 commented 2 years ago

Results are below.

args: camid=0, ckpt='tiny.pth', conf=0.3, demo='image', device='gpu', exp_file='exps/default/yolox_tiny.py', experiment_name='yolox_tiny', fp16=True, fuse=False, legacy=False, name=None, nms=0.3, path='fps/others', save_result=False, trt=False, tsize=416)

EXP files

nano:

def __init__(self):
        super(Exp, self).__init__()
        self.depth = 0.33
        self.width = 0.25
        self.input_size = (416, 416)
        self.random_size = (10, 20)
        self.mosaic_scale = (0.5, 1.5)
        self.test_size = (416, 416)
        self.mosaic_prob = 0.5
        self.enable_mixup = False
        self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
        self.num_classes =3
    def get_model(self, sublinear=False):
        def init_yolo(M):
            for m in M.modules():
                if isinstance(m, nn.BatchNorm2d):
                    m.eps = 1e-3
                    m.momentum = 0.03
        if "model" not in self.__dict__:
            from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
            in_channels = [256, 512, 1024]
            # NANO model use depthwise = True, which is main difference.
            backbone = YOLOPAFPN(
                self.depth, self.width, in_channels=in_channels,
                act=self.act, depthwise=True,
            )
            head = YOLOXHead(
                self.num_classes, self.width, in_channels=in_channels,
                act=self.act, depthwise=True
            )
            self.model = YOLOX(backbone, head)

        self.model.apply(init_yolo)
        self.model.head.initialize_biases(1e-2)
        return self.model

tiny:

def __init__(self):
        super(Exp, self).__init__()
        self.depth = 0.33
        self.width = 0.375
        self.input_size = (416, 416)
        self.mosaic_scale = (0.5, 1.5)
        self.random_size = (10, 20)
        self.test_size = (416, 416)
        self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
        self.enable_mixup = False
        self.num_classes = 3
ryotaro137 commented 2 years ago

Maybe because Dwconv in nano model don't adopt Xavier CPU. Ref:https://www.mdpi.com/2077-0472/12/6/856/pdf