自定义打印类信息:def __repr__(self)
2023-02-18 16:32:59 时间
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()
相关文章
- 如何让Redis兼顾效率、成本和运维?看vivo优化出妙招
- 微服务-技术专区-链路追踪(pinpoint)-部署使用
- 梳理总结-备份整理-知识点问题梳理
- MySQL-技术专区-mysql数据库权限管理
- MySQL-技术专区-数据库权限管理
- 开源软件的盈利模式
- 分布式-技术专区-Redis分布式锁实现-第二步
- Groovy系列(5)- Groovy IO操作
- 分布式-技术专区-Redis分布式锁实现-第一步
- JPA接口整理归纳方法规则
- 备份整理-实用归纳
- Groovy系列(4)- Groovy集合操作
- Groovy系列(3)- Groovy基础语法
- Zookeeper-技术专区-运作流程分析介绍
- 技术哲学-技术定位和思想
- Groovy系列(1)- Groovy简述
- Jmeter系列(30)- 性能指标(3) | 性能指标峰值
- Jmeter系列(29)- 性能指标(2) | 并发数
- 分布式-技术专区-Redis并发竞争key的解决方案详解
- Jmeter系列(28)- 性能指标(1) | 常见性能指标