- 如何打造数据治理闭环?以保[2022-06-16]
- 什么样的公司需要数据治理?[2022-06-15]
- “互联网+政务服务”下的数[2022-06-14]
- 我国数据安全治理研究[2022-06-13]
- 反洗钱视角下的数据治理[2022-06-10]
- 浅谈数据质量管理[2022-06-08]
- 做数据治理前,必须了解并避[2022-06-07]
- 企业数据治理团队的十大职[2022-06-06]
- 浅谈数据质量管理[2022-06-02]
- 数据治理的三种共享范式[2022-06-01]
教你使用torchlayers 来构建PyTorch 模型
通过在线搜索的趋势判断,PyTorch继续受到人们的普遍关注,更重要的是,PyTorch的使用率在不断提高。PyTorch被认为具有强大而灵活的特点,这些特点让其受到了研究者的欢迎。然而,PyTorch过去因缺乏简化的高级API(例如TensorFlow的Keras) 常常受到从业者的批评。但是这种情况最近已经改变了。
pip install --user torchlayers
-
torch.nn 和 torchlayers 层的混合使用
-
形状和维度推断(卷积、线性输入和BatchNorm)
-
默认的卷积核v大小
-
卷积的填充默认为 “same”
-
torchlayers池化层的使用(和Keras 相似,全局最大池化)
import torch
import torchlayers as tl
# torch.nn and torchlayers can be mixed easily
model = torch.nn.Sequential(
tl.Conv(64), # specify ONLY out_channels
torch.nn.ReLU(), # use torch.nn wherever you wish
tl.BatchNorm(), # BatchNormNd inferred from input
tl.Conv(128), # Default kernel_size equal to 3
tl.ReLU(),
tl.Conv(256, kernel_size=11), # "same" padding as default
tl.GlobalMaxPool(), # Known from Keras
tl.Linear(10), # Output for 10 classes
)
# Image...
mnist_model = tl.build(model, torch.randn(1, 3, 28, 28))
# ...or text
# [batch, embedding, timesteps], first dimension > 1 for BatchNorm1d to work
text_model = tl.build(model, torch.randn(2, 300, 1))
class _MyModuleImpl(torch.nn.Linear):
def post_build(self):
# You can do anything here really
torch.nn.init.eye_(self.weights)