Complete the code to import the necessary PyTorch module for building an FCN model.
import torch.nn as [1]
The nn module in PyTorch contains layers and functions to build neural networks, including FCNs.
Complete the code to define a convolutional layer with 3 input channels and 64 output channels.
conv_layer = nn.Conv2d([1], 64, kernel_size=3, padding=1)
The input channels for a color image are usually 3 (RGB), so the first argument is 3.
Fix the error in the forward method by completing the code to apply the final convolutional layer to the input.
def forward(self, x): x = self.conv_final([1]) return x
The input tensor to the layer is x, so we pass x to self.conv_final.
Fill both blanks to create a dictionary comprehension that maps each class index to its predicted pixel count in the segmentation output.
pixel_counts = {cls: (pred == [1]).sum().item() for cls in range([2])}We compare the prediction tensor pred to each class index cls and count pixels. The range is over num_classes.
Fill all three blanks to complete the training loop snippet that computes the loss, backpropagates, and updates the model parameters.
optimizer.zero_grad() outputs = model(inputs) loss = criterion(outputs, [1]) loss.[2]() optimizer.[3]()
The loss is computed comparing outputs to labels. Then loss.backward() computes gradients, and optimizer.step() updates weights.