temp

# def conv_bn(inp, oup, stride):
# return nn.Sequential(
# nn.Conv2d(inp, oup, 3, stride, 1, bias=False),
# nn.BatchNorm2d(oup),
# nn.ReLU(inplace=True)
# )

# def conv_dw(inp, oup, stride):
# return nn.Sequential(
# nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False),
# nn.BatchNorm2d(inp),
# nn.ReLU(inplace=True),

# nn.Conv2d(inp, oup, 1, 1, 0, bias=False),
# nn.BatchNorm2d(oup),
# nn.ReLU(inplace=True),
# )

# self.model = nn.Sequential(
# conv_bn( 3, 32, 2),
# conv_dw( 32, 64, 1),
# conv_dw( 64, 128, 2),
# conv_dw(128, 128, 1),
# conv_dw(128, 256, 2),
# conv_dw(256, 256, 1),
# conv_dw(256, 512, 2),
# conv_dw(512, 512, 1),
# conv_dw(512, 512, 1),
# conv_dw(512, 512, 1),
# conv_dw(512, 512, 1),
# conv_dw(512, 512, 1),
# conv_dw(512, 1024, 2),
# conv_dw(1024, 1024, 1),
# nn.AvgPool2d(7),
# )
# self.fc = nn.Linear(1024, 1000)

# def forward(self, x):
# x = self.model(x)
# x = x.view(-1, 1024)
# x = self.fc(x)
# return x
# class vgg16(_fasterRCNN):
# 11 def __init__(self, classes, pretrained=False, class_agnostic=False):
# 12 self.model_path = 'data/pretrained_model/vgg16_caffe.pth'
# 13 self.dout_base_model = 512
# 14 self.pretrained = pretrained
# 15 self.class_agnostic = class_agnostic
# 16
# 17 _fasterRCNN.__init__(self, classes, class_agnostic)
# 18
# 19 def _init_modules(self):
# 20 vgg = models.vgg16()
# 21 if self.pretrained:
# 22 print("Loading pretrained weights from %s" %(self.model_path))
# 23 state_dict = torch.load(self.model_path)
# 24 vgg.load_state_dict({k:v for k,v in state_dict.items() if k in vgg.state_dict()})
# 25
# 26 vgg.classifier = nn.Sequential(*list(vgg.classifier._modules.values())[:-1])
# 27
# 28 # not using the last maxpool layer
# 29 self.RCNN_base = nn.Sequential(*list(vgg.features._modules.values())[:-1])
# 30
# 31 # Fix the layers before conv3:
# 32 for layer in range(10):
# 33 for p in self.RCNN_base[layer].parameters(): p.requires_grad = False
# 34
# 35 # self.RCNN_base = _RCNN_base(vgg.features, self.classes, self.dout_base_model)
# 36
# 37 self.RCNN_top = vgg.classifier
# 38
# 39 # not using the last maxpool layer
# 40 self.RCNN_cls_score = nn.Linear(4096, self.n_classes)
# 41
# 42 if self.class_agnostic:
# 43 self.RCNN_bbox_pred = nn.Linear(4096, 4)
# 44 else:
# 45 self.RCNN_bbox_pred = nn.Linear(4096, 4 * self.n_classes)
# 46
# 47 def _head_to_tail(self, pool5):
# 48
# 49 pool5_flat = pool5.view(pool5.size(0), -1)
# 50 fc7 = self.RCNN_top(pool5_flat)
# 51
# 52 return fc7

posted @ 2020-05-25 22:16  haiyanli  阅读(241)  评论(0编辑  收藏  举报