def __init__(self, S, L, means): self.S = S self.L = L self.means = means self.l2norm = L2Normalization() # RoI max pooling self.r_mac_pool = RoIPool(1, 1, 0.03125) self.pca_shift = Shift(2048) self.pca_shift.bias.data = torch.Tensor(np.load('centered2.npy')) self.pca_fc = nn.Linear(2048, 2048, bias=True) # Load the PCA weights learned with off-the-shelf Resnet101 self.pca_fc.weight.data = torch.Tensor(np.load('weights/pca_weight.npy')) self.pca_fc.bias.data = torch.Tensor(np.load('weights/pca_bias.npy'))
def __init__(self): super(OurNet, self).__init__() self.l2norm = L2Normalization() #RoI max pooling self.r_mac_pool = RoIPool(1, 1, 0.03125) #Define regional attention network self.region_attention = ContextAwareRegionalAttentionNetwork(spatial_scale = 0.03125) self.pca_shift = Shift(2048) self.pca_fc = nn.Linear(2048, 2048, bias=False) #Load the PCA weights learned with off-the-shelf Resnet101 self.pca_fc.weight.data = torch.Tensor(np.load('weights/pca_components.npy')) self.pca_shift.bias.data = torch.Tensor(np.load('weights/pca_mean.npy')) self.resnet = Resnet.resnet101(pretrained=False) #Load off-the-shelf Resnet101 of caffe version. dic = torch.load('weights/resnet101_caffeProto.pth', map_location=lambda storage, loc: storage) self.resnet.load_state_dict(dic, strict=False)