0
0
Prompt Engineering / GenAIml~10 mins

Image-to-image transformation in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load an image and convert it to a tensor for image-to-image transformation.

Prompt Engineering / GenAI
from PIL import Image
import torchvision.transforms as transforms

image = Image.open('input.jpg')
transform = transforms.Compose([
    transforms.ToTensor(),
])
tensor_image = [1](image)
Drag options to blanks, or click blank then click option'
AImage.open
Btransform
Ctransforms
DImage
Attempts:
3 left
💡 Hint
Common Mistakes
Using Image.open again instead of the transform.
Trying to call transforms directly without Compose.
2fill in blank
medium

Complete the code to define a simple convolutional layer for image-to-image transformation.

Prompt Engineering / GenAI
import torch.nn as nn

conv_layer = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=[1], padding=1)
Drag options to blanks, or click blank then click option'
A3
B1
C5
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using kernel size 1 which is too small to capture features.
Using kernel size 7 which is large and uncommon here.
3fill in blank
hard

Fix the error in the code to apply a ReLU activation after the convolutional layer.

Prompt Engineering / GenAI
import torch.nn.functional as F

output = F.[1](conv_layer(input_tensor))
Drag options to blanks, or click blank then click option'
Arelu
Bsigmoid
Csoftmax
Dtanh
Attempts:
3 left
💡 Hint
Common Mistakes
Using sigmoid which is less common for convolutional activations.
Using softmax which is for classification outputs.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps image filenames to their transformed tensors if the image size is greater than 256.

Prompt Engineering / GenAI
image_tensors = {filename: [1] for filename, image in images.items() if image.size[0] [2] 256}
Drag options to blanks, or click blank then click option'
Atransform(image)
Btransform
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform without calling it as a function.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps image names to their grayscale tensors if the height is less than 128.

Prompt Engineering / GenAI
grayscale_images = {name: [1](image.convert([2])) for name, image in dataset.items() if image.size[1] [3] 128}
Drag options to blanks, or click blank then click option'
Atransform
B'L'
C<
D'RGB'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'RGB' instead of 'L' for grayscale conversion.
Using '>' instead of '<' in the size condition.