【发布时间】:2020-12-18 15:05:22
【问题描述】:
问题1。
假设图像的形状为 (batchsize=100,height=28,width=28,channel=1)
如果我们把这张图片放在下面的模型 CNN 中,
class CNN(torch.nn.Module):
def __init__(self):
super().__init__()
# ImgIn shape=(100, 28, 28, 1)
# Image shape after Conv -> (100, 28, 28, 32)
# Image shape after Pool -> (100, 14, 14, 32)
self.layer1 = torch.nn.Sequential(
torch.nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1),
torch.nn.ReLU(),
torch.nn.MaxPool2d(kernel_size=2, stride=2))
# second layer
# ImgIn shape=(100, 14, 14, 32)
# Image shape after Conv ->(100, 14, 14, 64)
# Image shape after Pool ->(100, 7, 7, 64)
self.layer2 = torch.nn.Sequential(
torch.nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1),
torch.nn.ReLU(),
torch.nn.MaxPool2d(kernel_size=2, stride=2))
# THESE PART CONFUSE!!!
self.fc = torch.nn.Linear(7 * 7 * 64, 10, bias=True)
torch.nn.init.xavier_uniform_(self.fc.weight)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.view(out.size(0), -1)
out = self.fc(out)
return out
self.fc 之后图像的批量大小会发生什么。
是大小(batch_size=100,10)吗?
问题 2。
另外,我对小批量感到困惑。如果有 5 个 mini-batch,loss 为 [5,-5,4,-4,0],那么平均 loss 为零,那么即使每个 mini-batch 有 loss 神经网络也会停止训练?
问题 3。 神经网络可以表达我的复数矩阵乘法吗?
【问题讨论】:
-
欢迎来到 Stackoverflow!最好一次问一个问题,这个问题可能会因为注意力不集中而被关闭。批量大小保持不变(=100)。只要损失的梯度不为零,神经网络就会继续训练。第三个问题不清楚。
-
你是怎么得到这个损失的?它看到,您的代码缺少部分。是分类任务还是回归任务?
标签: python machine-learning deep-learning pytorch conv-neural-network