def __init__(self, topN=4): super(attention_net, self).__init__() self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.add_module('raw_fc', nn.Linear(512 * 4, LABEL_NUM)) self.proposal_net = ProposalNet() self.topN = topN self.concat_net = nn.Linear(2048 * (CAT_NUM + 1), LABEL_NUM) self.partcls_net = nn.Linear(512 * 4, LABEL_NUM) _, edge_anchors, _ = generate_default_anchor_maps() self.pad_side = 224 self.edge_anchors = (edge_anchors + 224).astype(np.int)
def __init__(self, topN=4): super(attention_net, self).__init__() self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.avgpool = nn.AdaptiveAvgPool2d(1) self.pretrained_model.fc = nn.Linear(512 * 4, 200) self.proposal_net = ProposalNet() self.topN = topN self.concat_net = nn.Linear(2048 * (CAT_NUM + 1), 200) self.partcls_net = nn.Linear(512 * 4, 200) _, edge_anchors, _ = generate_default_anchor_maps() self.pad_side = 224 self.edge_anchors = (edge_anchors + 224).astype(np.int)
def __init__(self, topN=4): super(attention_net, self).__init__() self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.avgpool = nn.AdaptiveAvgPool2d(1) self.pretrained_model.fc = nn.Linear(512 * 4, NUM_CLASS) self.proposal_net = ProposalNet() self.topN = topN # proposal number self.concat_net = nn.Linear(2048 * (CAT_NUM + 1), NUM_CLASS) self.partcls_net = nn.Linear(512 * 4, NUM_CLASS) #其中每行的4个值[公式]表示矩形左上角和右下角点坐标。9个矩形共有3种形状,3种长宽比 _, edge_anchors, _ = generate_default_anchor_maps() self.pad_side = 224 self.edge_anchors = (edge_anchors + 224).astype(np.int)
def __init__(self, topN=4): super(attention_net, self).__init__() # self.pretrained_model = densenet.densenet201(pretrained=True) self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.avgpool = nn.AdaptiveAvgPool2d( 1) # 1 denotes the output size num_features = self.pretrained_model.num_features self.pretrained_model.fc = nn.Linear( num_features, NUM_CLS) # in_features=512*4, out_features=200 self.proposal_net = ProposalNet(num_features) self.topN = topN self.concat_net = nn.Linear(num_features * (CAT_NUM + 1), NUM_CLS) self.partcls_net = nn.Linear(num_features, NUM_CLS) _, edge_anchors, _ = generate_default_anchor_maps() self.pad_side = 224 self.edge_anchors = (edge_anchors + 224).astype(np.int)
def __init__(self, topN=4, n_class=200): super(attention_net, self).__init__() self.n_class = n_class self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.avgpool = nn.AdaptiveAvgPool2d(1) self.pretrained_model.fc = nn.Linear(512 * 4, self.n_class) self.proposal_net = ProposalNet() self.topN = topN self.concat_net = nn.Linear(2048 * (CAT_NUM + 1 + 1), self.n_class) self.partcls_net = nn.Linear(512 * 4, self.n_class) self.pad_side = 224 _, edge_anchors_small, _ = generate_default_anchor_maps( setting='small') self.edge_anchors_small = (edge_anchors_small + 224).astype(np.int) _, edge_anchors_large, _ = generate_default_anchor_maps( setting='large') self.edge_anchors_large = (edge_anchors_large + 224).astype(np.int)
def __init__(self): self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.avgpool = nn.AdaptiveAvgPool2d(1) self.pretrained_model.fc = nn.Linear(512 * 4, 200)
trainset = dataset.CUB(root="./CUB_200_2011", is_train=True, data_len=None) trainloader = torch.utils.data.DataLoader(trainset, batch_size=BATCH_SIZE, shuffle=True, num_workers=8, drop_last=False) testset = dataset.CUB(root="./CUB_200_2011", is_train=False, data_len=None) testloader = torch.utils.data.DataLoader(testset, batch_size=BATCH_SIZE, shuffle=False, num_workers=8, drop_last=False) # define model net = resnet.resnet50(pretrained=True) net.avgpool = torch.nn.AdaptiveAvgPool2d(1) net.fc = torch.nn.Linear(512 * 4, 200) if resume: ckpt = torch.load(resume) net.load_State_dict(ckpt["net_state_dict"]) start_epoch = ckpt["epoch"] + 1 creterion = torch.nn.CrossEntropyLoss() # define optimizers raw_parameters = list(net.parameters()) raw_optimizer = torch.optim.SGD(raw_parameters, lr=LR, momentum=0.9, weight_decay=WD)