当前位置:   article > 正文

PyTorch深度学习(8)Sequential及小神经网络搭建_"self . model = nn . sequential ( nn .conv2d(3,32,

"self . model = nn . sequential ( nn .conv2d(3,32,5,1, padding =\" same \")"

CIFAR10

神经网络

卷积层Conv公式

 Hin=32  Hout=32  padding=未知  dilation=1  kernel_size=5  stride=1

32 = (32 + 2 × padding - 1 × (5 - 1) - 1) / 1 + 1    得padding = 2

具体代码:

  1. import torch
  2. from torch import nn
  3. from torch.utils.tensorboard import SummaryWriter
  4. class TestSeq(nn.Module):
  5. def __init__(self):
  6. super(TestSeq, self).__init__()
  7. self.model = nn.Sequential(
  8. nn.Conv2d(3, 32, 5, padding=2),
  9. nn.MaxPool2d(2),
  10. nn.Conv2d(32, 32, 5, padding=2),
  11. nn.MaxPool2d(2),
  12. nn.Conv2d(32, 64, 5, padding=2),
  13. nn.MaxPool2d(2),
  14. nn.Flatten(),
  15. nn.Linear(1024, 64),
  16. nn.Linear(64, 10)
  17. )
  18. def forward(self, input):
  19. output = self.model(input)
  20. return output
  21. ts = TestSeq()
  22. print(ts)
  23. input_data = torch.ones((64, 3, 32, 32))
  24. output = ts(input_data)
  25. print(output.shape)
  26. writer = SummaryWriter("logs")
  27. writer.add_graph(ts, input_data)
  28. writer.close()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/537881
推荐阅读
相关标签
  

闽ICP备14008679号