ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

pyqtSignal()

2020-12-05 09:30:30  阅读:274  来源: 互联网

标签:loc nn pyqtSignal self conf 256 size


class GUI_progressBar(QWidget)
QWidget是所有用户界面对象的基类
class GUI_progressBar(QWidget):
    #声明无参数的信号
    close = pyqtSignal()
    #声明一个带参数的信号
    model = pyqtSignal(SSD) #SSD为class SSD(nn.Module)

         

class SSD(nn.Module):
    """Single Shot Multibox Architecture
    The network is composed of a base VGG network followed by the
    added multibox conv layers.  Each multibox layer branches into
        1) conv2d for class conf scores
        2) conv2d for localization predictions
        3) associated priorbox layer to produce default bounding
           boxes specific to the layer's feature map size.
    See: https://arxiv.org/pdf/1512.02325.pdf for more details.

    Args:
        phase: (string) Can be "test" or "train"
        size: input image size
        base: VGG16 layers for input, size of either 300 or 500
        extras: extra layers that feed to multibox loc and conf layers
        head: "multibox head" consists of loc and conf conv layers
    """

    def __init__(self, phase, size, base, extras, head, num_classes):
        super(SSD, self).__init__()
        self.phase = phase
        self.num_classes = num_classes
        self.cfg = (coco, voc)[num_classes == 2]
        self.priorbox = PriorBox(self.cfg)
        self.priors = Variable(self.priorbox.forward(), volatile=True)
        self.size = size

        # SSD network
        self.resnet18 = ResNet(BasicBlock, [2, 2, 2, 2], 3)
        # Layer learns to scale the l2 normalized features from conv4_3
        self.L2Norm = L2Norm(512, 20)
        self.extras = nn.ModuleList(extras)

        # FPN

        self.p3_lateral = nn.Conv2d(128, 256, kernel_size=1, stride=1, padding=0, bias=False)
        self.p4_lateral = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0, bias=False)
        self.p5_lateral = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0)
        self.p7_lateral = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0)
        self.p8_lateral = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0)

        # smooth
        self.p3_smooth = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
        self.p4_smooth = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
        self.p5_smooth = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
        self.p7_smooth = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
        self.p8_smooth = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)

        # detect
        self.loc = nn.ModuleList(head[0])
        self.conf = nn.ModuleList(head[1])

        if phase == 'test':
            self.softmax = nn.Softmax(dim=-1)
            self.detect = Detect(num_classes, 0, 200, 0.01, 0.45)


    def _upsample_add(self, x, y):
        _,_,H,W = y.size()
        return F.upsample(x, size=(H,W), mode='bilinear') + y


    def forward(self, x):
        """Applies network layers and ops on input image(s) x.

        Args:
            x: input image or batch of images. Shape: [batch,3,300,300].

        Return:
            Depending on phase:
            test:
                Variable(tensor) of output class label predictions,
                confidence score, and corresponding location predictions for
                each object detected. Shape: [batch,topk,7]

            train:
                list of concat outputs from:
                    1: confidence layers, Shape: [batch*num_priors,num_classes]
                    2: localization layers, Shape: [batch,num_priors*4]
                    3: priorbox layers, Shape: [2,num_priors*4]
        """
        sources = list()
        loc = list()
        conf = list()

        x = self.resnet18.maxpool(self.resnet18.relu(self.resnet18.bn1(self.resnet18.conv1(x))))
        res2b = self.resnet18.layer1(x)
        res3b = self.resnet18.layer2(res2b)
        res4b = self.resnet18.layer3(res3b)
        res5b = self.resnet18.layer4(res4b)

        # apply extra layers and cache source layer outputs
        c = list()
        x = res5b
        for k, v in enumerate(self.extras):
            x = F.relu(v(x), inplace=True)
            if k % 2 == 1:
                c.append(x)
        c7 = c[0]
        c8 = c[1]
        c9 = c[2]

        # FPN
        p8 = self._upsample_add(c9, self.p8_lateral(c8))
        p7 = self._upsample_add(p8, self.p7_lateral(c7))
        p5 = self._upsample_add(p7, self.p5_lateral(res5b))
        p4 = self._upsample_add(p5, self.p4_lateral(res4b))
        p3 = self._upsample_add(p4, self.p3_lateral(res3b))

        # smooth
        p8 = self.p8_smooth(p8)
        p7 = self.p8_smooth(p7)
        p5 = self.p8_smooth(p5)
        p4 = self.p8_smooth(p4)
        p3 = self.p8_smooth(p3)

        sources = [p3, p4, p5, p7, p8, c9]

        # apply multibox head to source layers
        for (x, l, c) in zip(sources, self.loc, self.conf):
            loc.append(l(x).permute(0, 2, 3, 1).contiguous())
            conf.append(c(x).permute(0, 2, 3, 1).contiguous())

        loc = torch.cat([o.view(o.size(0), -1) for o in loc], 1)
        conf = torch.cat([o.view(o.size(0), -1) for o in conf], 1)
        if self.phase == "test":
            output = self.detect(
                loc.view(loc.size(0), -1, 4),                   # loc preds
                self.softmax(conf.view(conf.size(0), -1,
                             self.num_classes)),                # conf preds
                self.priors.type(type(x.data))                  # default boxes
            )
        else:
            output = (
                loc.view(loc.size(0), -1, 4),
                conf.view(conf.size(0), -1, self.num_classes),
                self.priors
            )
        return output

    def load_weights(self, base_file):
        other, ext = os.path.splitext(base_file)
        if ext == '.pkl' or '.pth':
            print('Loading weights into state dict...')
            self.load_state_dict(torch.load(base_file,
                                 map_location=lambda storage, loc: storage))
            print('Finished!')
        else:
            print('Sorry only .pth and .pkl files supported.')

 

 

 

标签:loc,nn,pyqtSignal,self,conf,256,size
来源: https://blog.csdn.net/qq_16792139/article/details/110676896

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有