SSTato / YOLOv7_obb

Rotating object detection using YOLOv7 and CSL.
GNU General Public License v3.0
26 stars 3 forks source link

Layer fuse issue #5

Closed Suppersine closed 10 months ago

Suppersine commented 1 year ago

I ran into this problem again, is DWConv really defined or not?


     Epoch   gpu_mem       box       obj       cls     theta    labels  img_size
       4/4     12.7G    0.1369   0.03702         0    0.2512       126      1024: 100% 142/142 [01:20<00:00,  1.77it/s]
               Class     Images     Labels          P          R  HBBmAP@.5  HBBmAP@.5:.95: 100% 7/7 [00:03<00:00,  2.30it/s]
                 all         68       1018     0.0741      0.227      0.035    0.00802

5 epochs completed in 0.152 hours.
Optimizer stripped from runs/train/exp/weights/last.pt, 77.2MB
Optimizer stripped from runs/train/exp/weights/best.pt, 77.2MB

Validating runs/train/exp/weights/best.pt...
Fusing layers... 
Traceback (most recent call last):
  File "train.py", line 656, in <module>
    main(opt)
  File "train.py", line 553, in main
    train(opt.hyp, opt, device, callbacks)
  File "train.py", line 445, in train
    model=attempt_load(f, device).half(),
  File "/content/yolov7_obb_expm/models/experimental.py", line 282, in attempt_load
    model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval())  # FP32 model
  File "/content/yolov7_obb_expm/models/yolo.py", line 382, in fuse
    elif isinstance(m, DWConv) and hasattr(m, 'bn'):
TypeError: isinstance() arg 2 must be a type or tuple of types

Whose yolo.py code is here

    def fuse(self):  # fuse model Conv2d() + BatchNorm2d() layers
        LOGGER.info('Fusing layers... ')
        for m in self.model.modules():
            if isinstance(m, Conv) and hasattr(m, 'bn'):
                m.conv = fuse_conv_and_bn(m.conv, m.bn)  # update conv
                delattr(m, 'bn')  # remove batchnorm
                m.forward = m.forward_fuse  # update forward
            elif isinstance(m, DWConv) and hasattr(m, 'bn'):
                m.conv = fuse_conv_and_bn(m.conv, m.bn)  # update conv
                delattr(m, 'bn')  # remove batchnorm
                m.forward = m.forward_fuse  # update forward
            elif isinstance(m, RepConv):
                #print(f" fuse_repvgg_block")
                m.fuse_repvgg_block()
            elif isinstance(m, (IDetect)):
                m.fuse()
                m.forward = m.fuseforward
        self.info()
        return self
SSTato commented 1 year ago

So, there is no problem in your training stage. The problem is in the verification stage, right?

Suppersine commented 1 year ago

Yep. I was successful in the training stage, but not the detection stage

SSTato commented 1 year ago

From the log, we can see that you have generated the final weight file. As far as I know, my code can perform val and detect normally