Question 1: Short answer
hardAI-checkedConvolutional Neural NetworksA dense layer on top of a feature map is converted into a convolutional layer:
import torch
import torch.nn as nn
torch.manual_seed(0)
dense = nn.Linear(64 * 7 * 7, 10)
conv = nn.Conv2d(64, 10, kernel_size=7) # "valid" padding, stride 1
conv.weight.data = dense.weight.data.view(10, 64, 7, 7)
conv.bias.data = dense.bias.data
x = torch.randn(1, 64, 7, 7)
print(torch.allclose(dense(x.flatten(1)), conv(x).flatten(1), atol=1e-5))
print(conv(torch.randn(1, 64, 9, 9)).shape)
The first line prints True. What does the second line print?