Build a small two-layer convolutional network as an nn.Module and run a forward pass.
Signature: def conv_forward(x, w1, b1, w2, b2, stride1=1, padding1=0, stride2=1, padding2=0)
x: input (N, C_in, H, W) (nested list)w1: first conv weight (C_mid, C_in, kH1, kW1)b1: first conv bias (C_mid,)w2: second conv weight (C_out, C_mid, kH2, kW2)b2: second conv bias (C_out,)stride1/padding1: conv1 hyperparamsstride2/padding2: conv2 hyperparamsconv2 ∘ ReLU ∘ conv1 as a nested listWhat you must do:
nn.Module subclass whose __init__ creates self.conv1 = nn.Conv2d(...), self.relu = nn.ReLU(), and self.conv2 = nn.Conv2d(...) with the right channel and kernel sizes inferred from the weight tensors.forward(x): return self.conv2(self.relu(self.conv1(x))).torch.no_grad() with .copy_(), run the forward pass, return the output as a nested list.This problem covers forward only — there is no backward computation required.
Math
Asked at
import numpy as np
def conv_forward(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?