YOLOV5/YOLOV7改进:加入Repvgg并进行推理转化

 Repvgg简介:

c9d77494a484490b92dd5cf575983d45.png

理解结构重参数化的实质:训练时的结构对应一组参数,推理时我们想要的结构对应另一组参数;只要能把前者的参数等价转换为后者,就可以将前者的结构等价转换为后者。

Repvgg在推理阶段要进行推理转化,训练完的模型是未经过转化的,这样直接用来推理可能速度比原来还慢,所以要将转化的代码加到YOLOV5/YOLOV7的代码中。步骤如下:

1.新建 se_block.py,将下列代码加入

import torch
import torch.nn as nn
import torch.nn.functional as F

#   https://openaccess.thecvf.com/content_cvpr_2018/html/Hu_Squeeze-and-Excitation_Networks_CVPR_2018_paper.html

class SEBlock(nn.Module):

    def __init__(self, input_channels, internal_neurons):
        super(SEBlock, self).__init__()
        self.down = nn.Conv2d(in_channels=input_channels, out_channels=internal_neurons, kernel_size=1, stride=1, bias=True)
        self.up = nn

猜你喜欢

转载自blog.csdn.net/m0_51530640/article/details/128767224