def __init__(self, in_features, out_features, *, hids=[16], acts=['relu'], dropout=0.5, weight_decay=5e-4, lr=0.01, bias=False): super().__init__() conv = [] conv.append(nn.Dropout(dropout)) for hid, act in zip(hids, acts): conv.append(GraphConvolution(in_features, hid, bias=bias)) conv.append(activations.get(act)) conv.append(nn.Dropout(dropout)) in_features = hid conv.append(GraphConvolution(in_features, out_features, bias=bias)) conv = Sequential(*conv) self.conv = conv self.compile( loss=nn.CrossEntropyLoss(), optimizer=optim.Adam([ dict(params=conv[1].parameters(), weight_decay=weight_decay), dict(params=conv[2:].parameters(), weight_decay=0.) ], lr=lr), metrics=[Accuracy()])
def __init__(self, in_channels, out_channels, hids=[64], acts=[None], lambda_=5.0, gamma=0.1, dropout=0.5, weight_decay=5e-4, lr=0.01, use_bias=False): super().__init__() self.lambda_ = lambda_ self.gamma = gamma layers = nn.ModuleList() inc = in_channels for hid, act in zip(hids, acts): layer = GraphConvolution(inc, hid, activation=act, use_bias=use_bias) layers.append(layer) inc = hid layer = GraphConvolution(inc, out_channels, use_bias=use_bias) layers.append(layer) self.layers = layers self.scores = nn.ParameterList() self.bias = nn.ParameterList() self.D_k = nn.ParameterList() self.D_bias = nn.ParameterList() for hid in [in_channels] + hids: self.scores.append(nn.Parameter(torch.FloatTensor(hid, 1))) self.bias.append(nn.Parameter(torch.FloatTensor(1))) self.D_k.append(nn.Parameter(torch.FloatTensor(hid, 1))) self.D_bias.append(nn.Parameter(torch.FloatTensor(1))) # discriminator for ssl self.linear = nn.Linear(hids[-1], 1) self.compile(loss=torch.nn.CrossEntropyLoss(), optimizer=optim.Adam(self.parameters(), lr=lr, weight_decay=weight_decay), metrics=[Accuracy()]) self.dropout = nn.Dropout(dropout) self.reset_parameters()
def __init__(self, in_features, out_features, hids=[64], acts=[None], lambda_=5.0, gamma=0.1, dropout=0.5, weight_decay=5e-4, lr=0.01, bias=False): super().__init__() self.lambda_ = lambda_ self.gamma = gamma assert hids, "hids should not empty" layers = nn.ModuleList() act_layers = nn.ModuleList() inc = in_features for hid, act in zip(hids, acts): layers.append(GraphConvolution(in_features, hid, bias=bias)) act_layers.append(activations.get(act)) inc = hid layers.append(GraphConvolution(inc, out_features, bias=bias)) act_layers.append(activations.get(None)) self.layers = layers self.act_layers = act_layers self.scores = nn.ParameterList() self.bias = nn.ParameterList() self.D_k = nn.ParameterList() self.D_bias = nn.ParameterList() for hid in [in_features] + hids: self.scores.append(nn.Parameter(torch.FloatTensor(hid, 1))) self.bias.append(nn.Parameter(torch.FloatTensor(1))) self.D_k.append(nn.Parameter(torch.FloatTensor(hid, 1))) self.D_bias.append(nn.Parameter(torch.FloatTensor(1))) # discriminator for ssl self.linear = nn.Linear(hids[-1], 1) self.compile(loss=nn.CrossEntropyLoss(), optimizer=optim.Adam(self.parameters(), lr=lr, weight_decay=weight_decay), metrics=[Accuracy()]) self.dropout = nn.Dropout(dropout) self.reset_parameters()
def __init__(self, in_channels, out_channels, hiddens=[16], activations=['relu'], dropout=0.5, weight_decay=5e-4, lr=0.01, use_bias=False): super().__init__() self.layers = ModuleList() paras = [] # use ModuleList to create layers with different size inc = in_channels for hidden, activation in zip(hiddens, activations): layer = GraphConvolution(inc, hidden, activation=activation, use_bias=use_bias) self.layers.append(layer) paras.append( dict(params=layer.parameters(), weight_decay=weight_decay)) inc = hidden layer = GraphConvolution(inc, out_channels, use_bias=use_bias) self.layers.append(layer) # do not use weight_decay in the final layer paras.append(dict(params=layer.parameters(), weight_decay=0.)) self.compile(loss=torch.nn.CrossEntropyLoss(), optimizer=optim.Adam(paras, lr=lr), metrics=[Accuracy()]) self.dropout = Dropout(dropout)
def __init__(self, in_channels, out_channels, hids=[16], acts=['relu'], dropout=0.5, weight_decay=5e-4, lr=0.01, use_bias=False): super().__init__() layers = nn.ModuleList() paras = [] acts_fn = [] # use ModuleList to create layers with different size inc = in_channels for hid, act in zip(hids, acts): layer = nn.Linear(inc, hid, bias=use_bias) layers.append(layer) acts_fn.append(get_activation(act)) paras.append( dict(params=layer.parameters(), weight_decay=weight_decay)) inc = hid conv = GraphConvolution(inc, out_channels, use_bias=use_bias) # do not use weight_decay in the final layer paras.append(dict(params=conv.parameters(), weight_decay=0.)) self.compile(loss=torch.nn.CrossEntropyLoss(), optimizer=optim.Adam(paras, lr=lr), metrics=[Accuracy()]) self.dropout = nn.Dropout(dropout) self.acts_fn = acts_fn self.layers = layers self.conv = conv