【问题标题】:Where are those numbers coming from in pytorch neural networks?pytorch 神经网络中的这些数字来自哪里?
【发布时间】:2020-11-10 02:46:43
【问题描述】:

我是 Pytorch (python) 的新手,我刚刚浏览了他们的官方教程,发现了这个简单的神经网络架构。一切都很清楚,但是那些数字,最后三个全连接层,它们来自哪里?

self.fc1 = nn.Linear(16 * 6 * 6, 120)  # 6*6 from image dimension and 16 from last conv layer
self.fc2 = nn.Linear(120, 84) # but here, 120? 84? why? is this just random or there is some logic behind it?
self.fc3 = nn.Linear(84, 10) 

完整代码 - https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html#sphx-glr-beginner-blitz-neural-networks-tutorial-py

【问题讨论】:

    标签: python-3.x pytorch conv-neural-network


    【解决方案1】:
    
    self.fc1 = nn.Linear(16 * 6 * 6, 120)
    self.fc2 = nn.Linear(120, 84) # you can use any number instead of 120 play with this number and see which gives you best result.
    self.fc3 = nn.Linear(84, 10) 
    

    120 是 first layer after conv layer 中的单位数,second layer 中的 84 和 last 中的 10 可能是 output layer 的维度,即。 10 种可能的分类类型。 你是正确的dimension of second and third layer is not fixedyou can try different value of num of units 并选择一个给你最好的结果。您可以使用它,但您也可以查看一些性能最佳的模型并遵循它们使用的结构。

    【讨论】:

    • 所以,据我所知,16 来自最后一个 conv 层,6x6 是图像尺寸,但是,还有另一个教程,其中有 3x32x32 图像但第一个 fc 层是 16x5x5 而不是 6x6 pytorch.org/tutorials/beginner/blitz/…
    • 所以 6*6 并不完全直接来自图像。在卷积神经网络中,图像经过一系列过滤层和池化层。这些 过滤层 和 池化层和这些层的一些填充会影响输入向量到下一层的维度。根据这些层中的不同填充,您可以在第一个全连接层中获得不同的维度。
    猜你喜欢
    • 2018-12-16
    • 2021-02-16
    • 2021-03-11
    • 2019-03-08
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    相关资源
    最近更新 更多