教你使用torchlayers 来构建PyTorch 模型(附链接)
本文约1200字,建议阅读5分钟

附链接:
https://github.com/szymonmaszke/torchlayers
pip install --user torchlayers torch.nn 和 torchlayers 层的混合使用
形状和维度推断(卷积、线性输入和BatchNorm)
默认的卷积核v大小
卷积的填充默认为 “same”
torchlayers池化层的使用(和Keras 相似,全局最大池化)
import torchimport torchlayers as tl# torch.nn and torchlayers can be mixed easilymodel = torch.nn.Sequential(tl.Conv(64), # specify ONLY out_channelstorch.nn.ReLU(), # use torch.nn wherever you wishtl.BatchNorm(), # BatchNormNd inferred from inputtl.Conv(128), # Default kernel_size equal to 3tl.ReLU(),tl.Conv(256, kernel_size=11), # "same" padding as defaulttl.GlobalMaxPool(), # Known from Kerastl.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 worktext_model = tl.build(model, torch.randn(2, 300, 1))
class _MyModuleImpl(torch.nn.Linear):def post_build(self):# You can do anything here reallytorch.nn.init.eye_(self.weights)
OpenAI is Adopting PyTorch... They Aren’t Alone
链接:https://www.kdnuggets.com/2020/01/openai-pytorch-adoption.html
Gentle Introduction to PyTorch 1.2
链接:https://www.kdnuggets.com/2019/09/gentle-introduction-pytorch-12.html
Tokenization and Text Data Preparation with TensorFlow & Keras
链接:https://www.kdnuggets.com/2020/03/tensorflow-keras-tokenization-text-data-prep.html
END
转自: 数据派THU 公众号;
版权声明:本号内容部分来自互联网,转载请注明原文链接和作者,如有侵权或出处有误请和我们联系。
合作请加QQ:365242293
数据分析(ID : ecshujufenxi )互联网科技与数据圈自己的微信,也是WeMedia自媒体联盟成员之一,WeMedia联盟覆盖5000万人群。

关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号随时掌握互联网精彩
- 1 习近平同马克龙交流互动的经典瞬间 7904860
- 2 黑龙江水库冰面下现13匹冰冻马 7809172
- 3 微信表情包戒烟再度翻红 7711990
- 4 2025你的消费习惯“更新”了吗 7616374
- 5 三星堆与秦始皇帝陵竟有联系 7524133
- 6 为啥今年流感如此厉害 7426410
- 7 劲酒如何成了年轻女性的神仙水 7332282
- 8 女子裤子内藏2斤多活虫入境被查 7234826
- 9 一身塑料过冬?聚酯纤维真是塑料瓶吗 7143960
- 10 中疾控流感防治七问七答 7039396






![弥音音ww浣溪沙丽塔女仆为您效命[持续更新]](https://imgs.knowsafe.com:8087/img/aideep/2025/12/6/84d59f3b18bb9a703549a8cac677df25.jpg?w=250)
数据分析
