コード例 #1
0
    def __init__(self, hidden_channels, num_layers):
        super(DeeperGCN, self).__init__()

        self.node_encoder = Linear(data.x.size(-1), hidden_channels)
        self.edge_encoder = Linear(data.edge_attr.size(-1), hidden_channels)

        self.layers = torch.nn.ModuleList()
        for i in range(1, num_layers + 1):
            conv = GENConv(hidden_channels,
                           hidden_channels,
                           aggr='softmax',
                           t=1.0,
                           learn_t=True,
                           num_layers=2,
                           norm='layer')
            norm = LayerNorm(hidden_channels, elementwise_affine=True)
            act = ReLU(inplace=True)

            layer = DeepGCNLayer(conv,
                                 norm,
                                 act,
                                 block='res+',
                                 dropout=0.1,
                                 ckpt_grad=i % 3)
            self.layers.append(layer)

        self.lin = Linear(hidden_channels, data.y.size(-1))
コード例 #2
0
    def __init__(self, num_layers=4, edge_agg='spatial', resample=0,
        num_features=1024, hidden_dim=128, linear_dim=64, use_edges=False, dropout=0.25, n_classes=4):
        super(PatchGCN_Surv, self).__init__()
        self.use_edges = use_edges
        self.size_dict_path = {"small": [1024, 512, 256], "big": [1024, 512, 384]}
        self.edge_agg = edge_agg
        self.num_layers = num_layers-1
        self.resample = resample

        if self.resample > 0:
            self.fc = nn.Sequential(*[nn.Dropout(self.resample), nn.Linear(1024, 128), nn.ReLU(), nn.Dropout(0.25)])
        else:
            self.fc = nn.Sequential(*[nn.Linear(1024, 128), nn.ReLU(), nn.Dropout(0.25)])

        self.layers = torch.nn.ModuleList()
        for i in range(1, self.num_layers+1):
            conv = GENConv(hidden_dim, hidden_dim, aggr='softmax',
                           t=1.0, learn_t=True, num_layers=2, norm='layer')
            norm = LayerNorm(hidden_dim, elementwise_affine=True)
            act = ReLU(inplace=True)
            layer = DeepGCNLayer(conv, norm, act, block='res', dropout=0.1, ckpt_grad=i % 3)
            self.layers.append(layer)

        self.path_phi = nn.Sequential(*[nn.Linear(hidden_dim*4, hidden_dim*4), nn.ReLU(), nn.Dropout(0.25)])
        self.path_attention_head = Attn_Net_Gated(L=hidden_dim*4, D=hidden_dim*4, dropout=dropout, n_classes=1)
        self.path_rho = nn.Sequential(*[nn.Linear(hidden_dim*4, hidden_dim*4), nn.ReLU(), nn.Dropout(dropout)])
        self.classifier = torch.nn.Linear(hidden_dim*4, n_classes)    
コード例 #3
0
    def __init__(self, in_channels, hidden_channels, out_channels, dropout):
        super().__init__()
        self.dropout = dropout

        self.lin = Linear(in_channels, hidden_channels)

        self.convs = torch.nn.ModuleList()
        for i in range(2):
            conv = GATConv(hidden_channels, hidden_channels, dropout=dropout)
            norm = BatchNorm1d(hidden_channels)
            act = LeakyReLU()
            self.convs.append(
                DeepGCNLayer(conv, norm, act, block='res+', dropout=dropout))

        self.mem1 = MemPooling(hidden_channels, 80, heads=5, num_clusters=10)
        self.mem2 = MemPooling(80, out_channels, heads=5, num_clusters=1)
コード例 #4
0
    def __init__(self, n_in_edge_props, n_in_node_props, n_hidden_channels,
                 n_out_node_props, num_layers):
        super(DeeperGCN, self).__init__()

        self.n_in_edge_props = n_in_edge_props
        self.n_in_node_props = n_in_node_props
        self.n_hidden_channels = n_hidden_channels
        self.n_out_node_props = n_out_node_props
        self.num_layers = num_layers

        # Transform the node and edge feature vectors into scalars in hidden channels
        self.node_encoder = torch.nn.Sequential(
            torch.nn.Linear(in_features=self.n_in_node_props,
                            out_features=self.n_hidden_channels))
        self.edge_encoder = torch.nn.Sequential(
            torch.nn.Linear(in_features=self.n_in_edge_props,
                            out_features=self.n_hidden_channels),
            torch.nn.Sigmoid())

        # Construct layers of graph convolutions. Use the DeepGCN architecture, which is comprised of
        # MLPs for each node, input being neighbour nodes and edge values, which is aggregated and added
        # as a residual to the previous node scalars
        self.layers = torch.nn.ModuleList()
        for i in range(self.num_layers):
            conv = GENConv(in_channels=self.n_hidden_channels,
                           out_channels=self.n_hidden_channels,
                           num_layers=2,
                           norm='layer',
                           t=1.0,
                           learn_t=True,
                           aggr='softmax')
            norm = torch.nn.LayerNorm(self.n_hidden_channels,
                                      elementwise_affine=True)
            activation = torch.nn.ReLU(inplace=True)

            layer = DeepGCNLayer(conv,
                                 norm,
                                 activation,
                                 block='res+',
                                 dropout=0.1)

            self.layers.append(layer)

        # Transform hidden channels to output properties
        self.lin_out = torch.nn.Linear(self.n_hidden_channels,
                                       self.n_out_node_props)
コード例 #5
0
    def __init__(self, num_node_features, num_edge_features,
                 node_hidden_channels, edge_hidden_channels, num_layers,
                 num_classes):
        super(MyDeeperGCN, self).__init__()

        self.node_encoder = ChebConv(num_node_features, node_hidden_channels,
                                     T)
        self.edge_encoder = Linear(num_edge_features, edge_hidden_channels)

        self.layers = torch.nn.ModuleList()
        for i in range(1, num_layers + 1):
            conv = NNConv(
                node_hidden_channels, node_hidden_channels,
                MapE2NxN(edge_hidden_channels,
                         node_hidden_channels * node_hidden_channels,
                         hidden_channels3))
            norm = LayerNorm(node_hidden_channels, elementwise_affine=True)
            act = ReLU(inplace=True)

            layer = DeepGCNLayer(conv,
                                 norm,
                                 act,
                                 block='res+',
                                 dropout=dropout1,
                                 ckpt_grad=i % 3)
            self.layers.append(layer)

        self.postition = PositionEncode(node_hidden_channels)
        self.transformer = torch.nn.TransformerEncoder(
            torch.nn.TransformerEncoderLayer(node_hidden_channels,
                                             8,
                                             256,
                                             dropout=0.2,
                                             activation='relu'), 2)

        self.lin = Linear(node_hidden_channels, num_classes)
        self.dropout = Dropout(dropout2)