Lesson 133 — Advanced

Vision: How Images Become Tokens

Ek image model ke andar jaate hi tokens mein tootti hai, aur is tootne ka tareeka hi decide karta hai ki image kitni mehngi padegi aur kya-kya dikh paayega. Is lesson mein hum patches, tiles, detail settings, resolution-based token cost aur full-image-vs-crops ke trade-off ko ek chhote Python example ke saath samjhenge.

⏱ 10 min• Advanced• Beyond Text: What a Multimodal Model Is

Patches aur vision encoder

Kya hai?

Vision encoder image ko ek grid mein kaat-ta hai — chhote squares jinhe patches kehte hain. Har patch ko ek vector (embedding) mein badla jaata hai, aur ye vectors hi transformer ko milte hain, jaise words ke token embeddings milte hain.

Kab kaam aata hai?

Jab bhi tum image upload karo — screenshot, invoice, product photo. Tumhara har visual request pehle is patch-grid se guzarta hai, aur isi hisaab se token bill banta hai.

Kahan milta hai?

Multimodal API ke andar (vision encoder), ya open vision models mein jo locally chalte hain. Tumhe directly encoder chalane ki zarurat nahi — par uska hisaab samajhna zaroori hai.

Model image ko "pixels ke raste" se nahi dekhta — wo grid ke squares dekhta hai. Isliye jitni high resolution, utne zyada patches, utne zyada tokens. Ek hi photo ko zoom karke bhejna ya chhota karke bhejna, dono ka matlab alag hai.

Yaad rakho: Patch ek fixed physical area cover karta hai. Badi image mein same object chhote pixels mein baith jaata hai — isliye resolution badhane se detail milti hai, par bill bhi badhta hai. Dono hamesha saath chalte hain.

Ek image kitne tokens ki?

# Token cost resolution (pixels) se chalti hai, file size (MB) se NAHI
def image_token_cost(width, height, patch=14, tiles=1):
    """Approx model — apne provider ki docs se exact formula verify karo."""
    tokens_per_tile = (224 // patch) ** 2     # ek tile ke andar ke patches
    return tokens_per_tile * tiles            # high-detail = zyada tiles

print(image_token_cost(512, 512))            # chhota image = kam tokens
print(image_token_cost(2048, 2048))          # bada screenshot = bill triple
Rule of thumb: Har image upload se pehle do sawaal: (1) kya is image ka har pixel chahiye, ya sirf ek region? (2) kya model ko poori resolution chahiye, ya thumbnail kaafi hai? Ye do sawaal aksar aadha bill bacha dete hain.

Tiling aur detail settings

# High-detail mode: badi image = tiles ka grid, har tile apne tokens
request_hi = {
    "type": "image_url",
    "image_url": {"url": "invoice.png", "detail": "high"}
}
request_lo = {
    "type": "image_url",
    "image_url": {"url": "invoice.png", "detail": "low"}   # ek fixed chhoti tile
}
# low: sirf "isme kya hai" wala gist  |  high: chhota text, tables, numbers bhi
Decision rule: Scene samajhna hai (kya photo mein hai?) → low detail. Chhota text, invoice number, chart label padhna hai → high detail, aur usse bhi behtar — crop karke bhejo.

Downscaling aur full image vs crops

Practical workflow: pehle ek overview bhejo, model se pucho ki kaunsa region matter karta hai, phir usi region ka high-res crop bhejo. Ye do-step approach zyada tar use cases mein ek bada full-res image bhejne se sasti aur accurate banti hai.

Pitfall: Downscale karke chhota text "padhwana" sabse kharab pattern hai — model text ka shape dekh kar guess kar lega, aur guess hamesha plausible dikhta hai. Chhota text chahiye toh crop + high detail, kabhi bhi full-image-shrink nahi.

Exercise

Question: Image ko chhote grid squares mein todne wale pieces ka technical naam kya hai?

Question: Image ki token cost uske file size (MB) se chalti hai ya resolution (pixels) se?

Question: Badi image ko chhote tiles mein kaat kar bhejne wale detail mode ka naam?

Question: Image tokens aur text tokens kis cheez ko share karte hain model ke andar?

Common mistakes

Desi example: Tile wala photographer

Ek bada hoarding shoot karna hai. Poori photo kheenchoge toh printer ko bhi utna hi area dena padega (full-res = zyada tokens). Aur agar hoarding ke ek corner ka rate list padhna hai toh usi corner ka close-up kheench lo — crop: zyada detail, kam kharcha:

text
full hoarding photo  -> sab dikh par chhota text gaya
rate-list ka close-up -> text clear, area chhota, bill chhota

# overview + targeted crops = best of both
Interview angle — yahan se sawaal aate hain
  • Q: Vision model image ko kaise dekhta hai? — Fixed grid mein patches, har patch ka apna embedding, phir wahi transformer.
  • Q: Token cost kis se scale karti hai? — Resolution (tiles/patches) se, file size se nahi. Detail setting isko control karti hai.
  • Q: High vs low detail kab? — Low: scene gist, sasta. High: chhota text, tables, numbers.
  • Q: Ek bada screenshot chhota karke bhejne se kya hota hai? — Chhota text, thin lines aur labels kho jaate hain; model phir bhi guess kar sakta hai.
Lesson complete?

Image-token ka economics clear — ab tum crop aur resolution ka trade-off consciously choose kar sakte ho. Agla lesson — Vision: Capabilities & Failure Modes — mein dekhenge model visual mein kya acche se karta hai aur kahan galat confident hota hai.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course