THU-MIG / yolov10

YOLOv10: Real-Time End-to-End Object Detection [NeurIPS 2024]
https://arxiv.org/abs/2405.14458
GNU Affero General Public License v3.0
9.9k stars 978 forks source link

Test speed with PyTorch #318

Open wsy-yjys opened 4 months ago

wsy-yjys commented 4 months ago

请问不export模型,直接在PyTorch环境中进行测速,除了修改v10Detect删除one2many之外,还需要注意什么吗?

wsy-yjys commented 4 months ago

在具体实现上,引入标志self.test_speed并将其设置为True,实现只计算one2one是否就可以?

class v10Detect(Detect):

    max_det = 300
    def __init__(self, nc=80, ch=()):
        super().__init__(nc, ch)
        c3 = max(ch[0], min(self.nc, 100))  # channels
        self.cv3 = nn.ModuleList(nn.Sequential(nn.Sequential(Conv(x, x, 3, g=x), Conv(x, c3, 1)), \
                                               nn.Sequential(Conv(c3, c3, 3, g=c3), Conv(c3, c3, 1)), \
                                                nn.Conv2d(c3, self.nc, 1)) for i, x in enumerate(ch))

        self.one2one_cv2 = copy.deepcopy(self.cv2)
        self.one2one_cv3 = copy.deepcopy(self.cv3)
        self.test_speed = True

    def forward(self, x):
        one2one = self.forward_feat([xi.detach() for xi in x], self.one2one_cv2, self.one2one_cv3)
        if self.test_speed:
            one2one = self.inference(one2one)
            return {"one2one": one2one}
Meansnj commented 3 months ago

请问这个问题你解决了吗