Skip to content
ml-recall

#fully-convolutional-network

1 question from Convolutional Neural Networks

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

hardAI-checkedConvolutional Neural Networks

A dense layer on top of a 64×7×764 \times 7 \times 7 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?

Four dimensions in order, e.g. (1, 16, 10, 10)