Complete the code to load a low-resolution image using OpenCV.
import cv2 low_res_img = cv2.imread([1]) print(low_res_img.shape)
We load the low-resolution image file named 'low_res_image.jpg' to start super-resolution.
Complete the code to resize the low-resolution image to a higher resolution using OpenCV.
high_res_img = cv2.resize(low_res_img, [1], interpolation=cv2.INTER_CUBIC) print(high_res_img.shape)
We resize the image to a larger size (256x256) to simulate super-resolution output.
Fix the error in the code to define a simple super-resolution model using PyTorch.
import torch.nn as nn class SimpleSR(nn.Module): def __init__(self): super(SimpleSR, self).__init__() self.conv1 = nn.Conv2d(3, 64, kernel_size=[1], padding=1) def forward(self, x): return self.conv1(x)
The kernel size should be 3 to keep the output size consistent with padding=1.
Fill both blanks to complete the training loop snippet for super-resolution model.
for epoch in range(num_epochs): for data in dataloader: inputs, targets = data optimizer.zero_grad() outputs = model([1]) loss = criterion(outputs, [2]) loss.backward() optimizer.step()
We pass inputs to the model and compare outputs with targets to compute loss.
Fill all three blanks to create a dictionary comprehension that maps image names to their super-resolution outputs.
sr_results = [1]: model(images[[2]].unsqueeze(0)) for [3] in images.keys()}
We use 'name' as the key and loop variable, and access images by 'name' to get the input tensor.