All problems
SAM Prompt Encoder
Problem
Build sparse prompt embeddings for the Segment Anything prompt encoder. Each point contributes [x, y, is_positive, is_background], where the label 1 sets is_positive and the label 0 sets is_background.
The signature is sam_prompt_encoder(points, labels). Return the list of embeddings.
Hint
Positive clicks select an object while negative clicks exclude regions.
Test cases
case 1
in: [[[0.5,0.5]],[1]]
expected: [[0.5,0.5,1,0]]
case 2
in: [[[0.1,0.2]],[0]]
expected: [[0.1,0.2,0,1]]
case 3
in: [[[-0.5,1.5],[0.3,0.3]],[1,0]]
expected: [[-0.5,1.5,1,0],[0.3,0.3,0,1]]
case 4
in: [[[0,0]],[1]]
expected: [[0,0,1,0]]
Starter codePython
def sam_prompt_encoder(points, labels):
# Your code here
pass4 test cases · run your code against them in the editor