0
0
Computer Visionml~10 mins

Semantic segmentation vs instance segmentation in Computer Vision - Interactive Practice

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

Complete the code to create a semantic segmentation mask using a simple threshold.

Computer Vision
import numpy as np

image = np.array([[100, 150], [200, 50]])
mask = image [1] 100
print(mask)
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will select the wrong pixels.
2fill in blank
medium

Complete the code to label connected components for instance segmentation.

Computer Vision
from scipy.ndimage import label

binary_mask = np.array([[1, 1, 0], [0, 1, 0], [0, 0, 1]])
labeled_mask, num_features = label([1])
print(labeled_mask, num_features)
Drag options to blanks, or click blank then click option'
Abinary_mask
Bimage
Cmask
Dnp.array
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the original image instead of the binary mask.
3fill in blank
hard

Fix the error in the code that tries to separate instances in a semantic mask.

Computer Vision
import numpy as np

semantic_mask = np.array([[1, 1, 0], [0, 1, 0], [0, 0, 1]])
instances = np.zeros_like(semantic_mask)
count = 1
for i in range(semantic_mask.shape[0]):
    for j in range(semantic_mask.shape[1]):
        if semantic_mask[i, j] [1] 1:
            instances[i, j] = count
            count += 1
print(instances)
Drag options to blanks, or click blank then click option'
A>
B==
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '>' causes wrong pixels to be labeled.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps instance ids to pixel counts.

Computer Vision
instance_counts = [1]: np.sum(instances == [2]) for [1] in np.unique(instances) if [2] != 0}
Drag options to blanks, or click blank then click option'
Ainstance_id
Bcount
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable for both keys and values incorrectly.
5fill in blank
hard

Fill all three blanks to create a function that returns the number of instances in a semantic mask.

Computer Vision
def count_instances(mask):
    unique_vals = np.unique(mask)
    count = sum(1 for val in unique_vals if val [1] 0)
    return count

mask = np.array([[0, 1, 1], [2, 0, 2]])
print(count_instances(mask))
Drag options to blanks, or click blank then click option'
A==
B>
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' or '<' includes background in the count.