人群计数——MCNN

这是对于Single-Image Crowd Counting via Multi-Column Convolutional Neural Network(2016 CVPR)中所提出的MCNN模型的基于pytorch的实现

import torch

#import torchstat as te;import numpy
class my_MCNN(torch.nn.Module):
    def __init__(self):
        super(my_easy_MCNN,self).__init__()
        self.conv9_1=torch.nn.Conv2d(3,16,9,padding=4)
        self.conv7_1_1=torch.nn.Conv2d(16,32,7,padding=3)
        self.conv7_1_2 = torch.nn.Conv2d(32, 16, 7,padding=3)
        self.conv7_1_3 = torch.nn.Conv2d(16, 8, 7,padding=3)
        self.conv7_2_1 = torch.nn.Conv2d(3, 20, 7,padding=3)
        self.conv5_2_1 = torch.nn.Conv2d(20, 40, 5,padding=2)
        self.conv5_2_2 = torch.nn.Conv2d(40, 20, 5,padding=2)
        self.conv5_2_3 = torch.nn.Conv2d(20, 10, 5,padding=2)
        self.conv5_3_1 = torch.nn.Conv2d(3, 24, 5,padding=2)
        self.conv3_3_1 = torch.nn.Conv2d(24, 48, 3,padding=1)
        self.conv3_3_2 = torch.nn.Conv2d(48, 24, 3,padding=1)
        self.conv3_3_3 = torch.nn.Conv2d(24, 12, 3,padding=1)
        #补零是为了让三个分支输出形状相同
        self.maxpool=torch.nn.MaxPool2d(2)
        self.relu=torch.nn.functional.relu
        self.fuse=torch.nn.Conv2d(30,1,1)

    def forward(self,x):
        b1=self.maxpool(self.relu(self.conv9_1(x)))
        #print(b1.shape)
        b1 = self.maxpool(self.relu(self.conv7_1_1(b1)))
        b1=self.relu(self.conv7_1_2(b1))
        b1=self.relu(self.conv7_1_3(b1))
        b2 = self.maxpool(self.relu(self.conv7_2_1(x)))
        b2 = self.maxpool(self.relu(self.conv5_2_1(b2)))
        b2 = self.relu(self.conv5_2_2(b2))
        b2=self.relu(self.conv5_2_3(b2))
        b3 = self.maxpool(self.relu(self.conv5_3_1(x)))
        #print(b3.shape)
        b3 = self.maxpool(self.relu(self.conv3_3_1(b3)))
        b3 = self.relu(self.conv3_3_2(b3))
        b3 = self.relu(self.conv3_3_3(b3))
        y=torch.cat((b1,b2,b3),1)
        y=self.fuse(y)
        return y
class mynet(torch.nn.Module):
    def __init__(self):
        super(mynet,self).__init__()
        mynet.c=torch.nn.Linear(1200,1,5)
    def forward(self,x):
        h=self.c(x)
        return h


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值