Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-262

SAM Mask Decoder

Problem

Decode binary masks by dotting each mask token against every image feature position and thresholding the logits at zero. Return one 0/1 mask per token.

The signature is sam_mask_decoder(image_features, mask_tokens). image_features is (num_positions, d) and mask_tokens is (num_masks, d).

Hint

Mask tokens act as dynamic filters over the upsampled image embedding.

Test cases

case 1
in: [[[1,0],[0,1]],[[1,0]]]
expected: [[1,0]]
case 2
in: [[[1,0],[0,1]],[[1,1]]]
expected: [[1,1]]
case 3
in: [[[1,1],[1,1]],[[1,0],[0,1]]]
expected: [[1,1],[1,1]]
case 4
in: [[[-1,0],[0,-1]],[[1,0]]]
expected: [[0,0]]
Starter codePython
def sam_mask_decoder(image_features, mask_tokens):
    # Your code here
    pass

4 test cases · run your code against them in the editor