标签:__ features 自定义 self torch def out
Example:
import torch import torch.nn.functional as F from torch.nn.modules.module import Module from torch.nn.parameter import Parameter class GraphConvolution(Module): def __init__(self, in_features, out_features, dropout=0., act=F.relu): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.dropout = dropout self.act = act self.weight = Parameter(torch.FloatTensor(in_features, out_features)) self.reset_parameters() def reset_parameters(self): torch.nn.init.xavier_uniform_(self.weight) def forward(self, input, adj): input = F.dropout(input, self.dropout, self.training) support = torch.mm(input, self.weight) output = torch.spmm(adj, support) output = self.act(output) return output # def __repr__(self): # return self.__class__.__name__ + ' (' \ # + str(self.in_features) + ' -> ' \ # + str(self.out_features) + ')' if __name__ =='__main__': gc = GraphConvolution(in_features=10, out_features=10, dropout=0., act=F.relu) print(gc)
加 def __repr__(self)
GraphConvolution (10 -> 10)
不加 def __repr__(self) :
GraphConvolution()
标签:__,features,自定义,self,torch,def,out 来源: https://www.cnblogs.com/BlairGrowing/p/16066265.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。