Skip to content
DeepForgeby svx
All problems
EasyComputer Visioncv-175

Image Token Count

Problem

Count the tokens a Vision Transformer produces for an image.

Number of patches = (h // patch) * (w // patch); add 1 for the CLS token when include_cls is True. Return the integer count.

Test cases

case 1
in: [224,224,16,true]
expected: 197
case 2
in: [224,224,16,false]
expected: 196
case 3
in: [32,32,8,true]
expected: 17
case 4
in: [64,96,16,false]
expected: 24
Starter codePython
def token_count(h, w, patch, include_cls):
    # Your code here
    pass

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