def __init__(self, embed_len, inst_num, c=0.05): # for downloading pretrained model super(MINet, self).__init__() self.inst_num = inst_num resnet18_pretn = models.resnet18(pretrained=True) pretn_state_dict = resnet18_pretn.state_dict() self.resnet18 = models.resnet18(num_classes=embed_len) model_state_dict = self.resnet18.state_dict() update_state = { k: v for k, v in pretn_state_dict.items() if k not in ["fc.weight", "fc.bias"] and k in model_state_dict } model_state_dict.update(update_state) self.resnet18.load_state_dict(model_state_dict) self.c = c self.tp = hypnn.ToPoincare(c=self.c, train_x=True, train_c=True, ball_dim=embed_len) self.att_weight = hypnn.HypLinear(embed_len, 1, c=self.c) self.label_pred = hypnn.HyperbolicMLR(ball_dim=embed_len, n_classes=2, c=self.c)
def __init__(self, args): super(Netold, self).__init__() self.conv1 = nn.Conv2d(3, 20, 5, 1) self.conv2 = nn.Conv2d(20, 50, 5, 1) self.fc1 = nn.Linear(4 * 4 * 50, 500) self.fc2 = nn.Linear(500, args.dim) self.tp = hypnn.ToPoincare( c=args.c, train_x=args.train_x, train_c=args.train_c, ball_dim=args.dim ) self.mlr = hypnn.HyperbolicMLR(ball_dim=args.dim, n_classes=120, c=args.c)
def __init__(self, args): super(NetHypConv2, self).__init__() self.tp = hypnn.ToPoincare(c=args.c, train_x=args.train_x, train_c=args.train_c, ball_dim=args.dim) self.conv1 = hypnn.HypConv2(1, 20, 5, c=args.c) self.conv2 = hypnn.HypConv2(20, 50, 5, c=args.c) self.fc1 = hypnn.HypLinear2(4 * 4 * 50, 500, c=args.c) self.fc2 = hypnn.HypLinear2(500, args.dim, c=args.c) self.mlr = hypnn.HyperbolicMLR(ball_dim=args.dim, n_classes=10, c=args.c)
def __init__(self, embed_len, inst_num, c=0.001): # for downloading pretrained model super(MINet, self).__init__() self.inst_num = inst_num self.lenet = LeNet(embed_len) self.c = c self.tp = hypnn.ToPoincare(c=self.c, train_x=True, train_c=False, ball_dim=embed_len) self.att_weight = hypnn.HypLinear(embed_len, 1, c=self.c) self.msi_pred = hypnn.HyperbolicMLR(ball_dim=embed_len, n_classes=2, c=self.c)
def __init__(self, args): super(NetHypConv, self).__init__() self.tp = hypnn.ToPoincare(c=args.c, train_x=args.train_x, train_c=args.train_c, ball_dim=args.dim) self.conv1 = hypnn.HypConv( 1, 20, 5, c=args.c) # input: 28 x 28, output: 20 x 24 x 24 (pool 2x2 after) self.conv2 = hypnn.HypConv( 20, 50, 5, c=args.c ) # input: 20 x 12 x 12, output: 50 x 8 x 8 (pool 2x2 after) self.fc1 = hypnn.HypLinear(4 * 4 * 50, 500, c=args.c) # input: 50 x 4 x 4, output: 500 self.fc2 = hypnn.HypLinear(500, args.dim, c=args.c) self.mlr = hypnn.HyperbolicMLR(ball_dim=args.dim, n_classes=10, c=args.c)