54 卷积层

import torch
import torch.nn as nn
import torch.nn.functional as F
layer = nn.Conv2d(1,3,kernel_size=3,stride=1,padding=0)  #1:input channel 3:kernal number
x = torch.rand(1,1,28,28)
out = layer.forward(x)
print(out.shape)
layer = nn.Conv2d(1,3,kernel_size=3,stride=2,padding=1)  #1:input channel 3:kernal number
out = layer.forward(x)
print(out.shape)
out = layer(x)
print(out.shape)
print(layer.weight)
print(layer.weight.shape)  # torch.Size([3, 1, 3, 3])
print(layer.bias.shape)
x = torch.rand(1,3,28,28)
w = torch.rand(16,3,5,5)
b = torch.rand(16)
out = F.conv2d(x, w, b, stride=1, padding=1)
print(out.shape)                  # torch.Size([1, 16, 26, 26])
# 卷积运算后第二个通道(3,RGB)消失了?为什么??

你可能感兴趣的:(54 卷积层)