我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用network.Conv2d()。
def __init__(self, bn=False): super(MCNN, self).__init__() self.branch1 = nn.Sequential(Conv2d( 1, 16, 9, same_padding=True, bn=bn), nn.MaxPool2d(2), Conv2d(16, 32, 7, same_padding=True, bn=bn), nn.MaxPool2d(2), Conv2d(32, 16, 7, same_padding=True, bn=bn), Conv2d(16, 8, 7, same_padding=True, bn=bn)) self.branch2 = nn.Sequential(Conv2d( 1, 20, 7, same_padding=True, bn=bn), nn.MaxPool2d(2), Conv2d(20, 40, 5, same_padding=True, bn=bn), nn.MaxPool2d(2), Conv2d(40, 20, 5, same_padding=True, bn=bn), Conv2d(20, 10, 5, same_padding=True, bn=bn)) self.branch3 = nn.Sequential(Conv2d( 1, 24, 5, same_padding=True, bn=bn), nn.MaxPool2d(2), Conv2d(24, 48, 3, same_padding=True, bn=bn), nn.MaxPool2d(2), Conv2d(48, 24, 3, same_padding=True, bn=bn), Conv2d(24, 12, 3, same_padding=True, bn=bn)) self.fuse = nn.Sequential(Conv2d( 30, 1, 1, same_padding=True, bn=bn))
def __init__(self, bn=False): super(VGG16, self).__init__() self.conv1 = nn.Sequential(Conv2d(3, 64, 3, same_padding=True, bn=bn), Conv2d(64, 64, 3, same_padding=True, bn=bn), nn.MaxPool2d(2)) self.conv2 = nn.Sequential(Conv2d(64, 128, 3, same_padding=True, bn=bn), Conv2d(128, 128, 3, same_padding=True, bn=bn), nn.MaxPool2d(2)) network.set_trainable(self.conv1, requires_grad=False) network.set_trainable(self.conv2, requires_grad=False) self.conv3 = nn.Sequential(Conv2d(128, 256, 3, same_padding=True, bn=bn), Conv2d(256, 256, 3, same_padding=True, bn=bn), Conv2d(256, 256, 3, same_padding=True, bn=bn), nn.MaxPool2d(2)) self.conv4 = nn.Sequential(Conv2d(256, 512, 3, same_padding=True, bn=bn), Conv2d(512, 512, 3, same_padding=True, bn=bn), Conv2d(512, 512, 3, same_padding=True, bn=bn), nn.MaxPool2d(2)) self.conv5 = nn.Sequential(Conv2d(512, 512, 3, same_padding=True, bn=bn), Conv2d(512, 512, 3, same_padding=True, bn=bn), Conv2d(512, 512, 3, same_padding=True, bn=bn))
def __init__(self, classes=None, debug=False): super(RFCN, self).__init__() if classes is not None: self.classes = classes self.n_classes = len(classes) self.rpn = RPN() #self.psroi_pool = PSRoIPool(7,7,1.0/16,7,15) This is for test self.psroi_pool_cls = PSRoIPool(7,7, 1.0/16, 7, self.n_classes) self.psroi_pool_loc = PSRoIPool(7,7, 1.0/16, 7, 8) self.new_conv = Conv2d(512, 1024, 1, same_padding=False) self.rfcn_score = Conv2d(1024,7*7*8, 1,1, bn=False) self.rfcn_bbox = Conv2d(1024, 7*7*self.n_classes,1,1,bn=False) self.bbox_pred = nn.AvgPool2d((7,7),stride=(7,7)) self.cls_score = nn.AvgPool2d((7,7),stride=(7,7)) # loss self.cross_entropy = None self.loss_box = None # for log self.debug = debug
def __init__(self): super(RPN, self).__init__() self.features = VGG16(bn=False) self.conv1 = Conv2d(512, 512, 3, same_padding=True) self.score_conv = Conv2d(512, len(self.anchor_scales) * 3 * 2, 1, relu=False, same_padding=False) self.bbox_conv = Conv2d(512, len(self.anchor_scales) * 3 * 4, 1, relu=False, same_padding=False) # loss self.cross_entropy = None self.los_box = None
def __init__(self, bn=False, num_classes=10): super(CMTL, self).__init__() self.num_classes = num_classes self.base_layer = nn.Sequential(Conv2d( 1, 16, 9, same_padding=True, NL='prelu', bn=bn), Conv2d(16, 32, 7, same_padding=True, NL='prelu', bn=bn)) self.hl_prior_1 = nn.Sequential(Conv2d( 32, 16, 9, same_padding=True, NL='prelu', bn=bn), nn.MaxPool2d(2), Conv2d(16, 32, 7, same_padding=True, NL='prelu', bn=bn), nn.MaxPool2d(2), Conv2d(32, 16, 7, same_padding=True, NL='prelu', bn=bn), Conv2d(16, 8, 7, same_padding=True, NL='prelu', bn=bn)) self.hl_prior_2 = nn.Sequential(nn.AdaptiveMaxPool2d((32,32)), Conv2d( 8, 4, 1, same_padding=True, NL='prelu', bn=bn)) self.hl_prior_fc1 = FC(4*1024,512, NL='prelu') self.hl_prior_fc2 = FC(512,256, NL='prelu') self.hl_prior_fc3 = FC(256, self.num_classes, NL='prelu') self.de_stage_1 = nn.Sequential(Conv2d( 32, 20, 7, same_padding=True, NL='prelu', bn=bn), nn.MaxPool2d(2), Conv2d(20, 40, 5, same_padding=True, NL='prelu', bn=bn), nn.MaxPool2d(2), Conv2d(40, 20, 5, same_padding=True, NL='prelu', bn=bn), Conv2d(20, 10, 5, same_padding=True, NL='prelu', bn=bn)) self.de_stage_2 = nn.Sequential(Conv2d( 18, 24, 3, same_padding=True, NL='prelu', bn=bn), Conv2d( 24, 32, 3, same_padding=True, NL='prelu', bn=bn), nn.ConvTranspose2d(32,16,4,stride=2,padding=1,output_padding=0,bias=True), nn.PReLU(), nn.ConvTranspose2d(16,8,4,stride=2,padding=1,output_padding=0,bias=True), nn.PReLU(), Conv2d(8, 1, 1, same_padding=True, NL='relu', bn=bn))
def __init__(self): super(RPN, self).__init__() self.features = VGG16(bn=False) #self.features = ResNet() self.conv1 = Conv2d(1024, 512, 3, same_padding=True) self.score_conv = Conv2d(512, len(self.anchor_scales) * 3 * 2, 1, relu=False, same_padding=False) self.bbox_conv = Conv2d(512, len(self.anchor_scales) * 3 * 4, 1, relu=False, same_padding=False) # loss self.cross_entropy = None self.los_box = None
def __init__(self): super(RPN, self).__init__() self.features = VGG16(bn=False) #self.features = ResNet() self.conv1 = Conv2d(512, 512, 3, same_padding=True) self.score_conv = Conv2d(512, len(self.anchor_scales) * 3 * 2, 1, relu=False, same_padding=False) self.bbox_conv = Conv2d(512, len(self.anchor_scales) * 3 * 4, 1, relu=False, same_padding=False) # loss self.cross_entropy = None self.los_box = None
def __init__(self, features): super(RPN, self).__init__() self.features = features # self.features = VGG16(bn=False) # (7, 7, 512) self.conv1 = Conv2d(512, 512, 3, same_padding=True) self.score_conv = Conv2d(512, len(self.anchor_scales) * 3 * 2, 1, relu=False, same_padding=False) self.bbox_conv = Conv2d(512, len(self.anchor_scales) * 3 * 4, 1, relu=False, same_padding=False) # loss self.cross_entropy = None self.los_box = None
def __init__(self, use_kmeans_anchors=False): super(RPN, self).__init__() if use_kmeans_anchors: print 'using k-means anchors' self.anchor_scales = self.anchor_scales_kmeans self.anchor_ratios = self.anchor_ratios_kmeans self.anchor_scales_region = self.anchor_scales_kmeans_region self.anchor_ratios_region = self.anchor_ratios_kmeans_region else: print 'using normal anchors' self.anchor_scales, self.anchor_ratios = \ np.meshgrid(self.anchor_scales_normal, self.anchor_ratios_normal, indexing='ij') self.anchor_scales = self.anchor_scales.reshape(-1) self.anchor_ratios = self.anchor_ratios.reshape(-1) self.anchor_scales_region, self.anchor_ratios_region = \ np.meshgrid(self.anchor_scales_normal_region, self.anchor_ratios_normal_region, indexing='ij') self.anchor_scales_region = self.anchor_scales_region.reshape(-1) self.anchor_ratios_region = self.anchor_ratios_region.reshape(-1) self.anchor_num = len(self.anchor_scales) self.anchor_num_region = len(self.anchor_scales_region) # self.features = VGG16(bn=False) self.features = models.vgg16(pretrained=True).features self.features.__delattr__('30') # to delete the max pooling # by default, fix the first four layers network.set_trainable_param(list(self.features.parameters())[:8], requires_grad=False) # self.features = models.vgg16().features self.conv1 = Conv2d(512, 512, 3, same_padding=True) self.score_conv = Conv2d(512, self.anchor_num * 2, 1, relu=False, same_padding=False) self.bbox_conv = Conv2d(512, self.anchor_num * 4, 1, relu=False, same_padding=False) self.conv1_region = Conv2d(512, 512, 3, same_padding=True) self.score_conv_region = Conv2d(512, self.anchor_num_region * 2, 1, relu=False, same_padding=False) self.bbox_conv_region = Conv2d(512, self.anchor_num_region * 4, 1, relu=False, same_padding=False) # loss self.cross_entropy = None self.loss_box = None self.cross_entropy_region = None self.loss_box_region = None # initialize the parameters self.initialize_parameters()