r/computervision • u/Safe-Escape197 • 17d ago
Discussion built a tiny vision model from scratch just for learning and somehow it got 50+ downloads on huggingface π
so ik there are way better vision models out there yaar. i built this one just out of curiosity only, cause i wanted to learn how these things actually work from inside.
and to be honest its not entirely mine, i took a lot of help from claude to build it. like the architecture, debugging, training setup, figuring out why my mac was training so slow, all that. but i learned a lot in the process which was the main goal anyway.
its called tiny-vision. its around 24M params and trained completely from scratch, no pretrained weights or anything. i trained it on my macbook pro m5 and it took like 42 min on flickr8k (only 6k images).
basic idea is pretty simple:
image/video β small ViT encoder β adapter β tiny decoder β caption text
for videos it takes frames every few seconds, captions them and makes a timeline like [00:04β00:10] a dog runs on the beach. so any llm can kinda βwatchβ a video even if it dont support video natively.
i also made an MCP server for it, and tbh i was surprised that it actually gives a little bit better context in claude when i throw images or videos at it. i even tested it with a 10-15 min youtube video and it still worked fine. not perfect at all, but chal raha hai so iβm happy.
i uploaded it to huggingface just to have it somewhere, and also cause i kinda like the open source thing. later when i checked it was at like 44 downloads, and now its 50+. ik thats not a lot bhai, but its my first time putting something open source out in this field so it felt pretty cool ngl. a lot of people have built way cooler stuff than this, i just made it to learn.
some honest stuff:
- it gets the scene right most of time (snow, grass, water etc) but the subject is often wrong lol
- it loves saying βa man in a blue shirtβ for everything, pata nahi kyun π
- its v0.1 and trained on very small data, so dont expect too much
random thing i learned on mac (MPS):
- swapping the conv2d patch embedding for reshape + linear was like 30x faster
- manual attention was ~1.5x faster than pytorchβs sdpa
next i want to train on flickr30k and maybe try making it plug directly into qwen/llama through llama.cpp (mmproj). lets see kitna ho pata hai.
code: https://github.com/amar683/tiny-vision
model: https://huggingface.co/amartomar683/tiny-vision-flickr8k
would love any feedback or tips,
1
u/No_Insurance_6174 17d ago
Nice work, building one from scratch is the best way to actually get how these things work. The "a man in a blue shirt" thing is pretty classic for Flickr8k, the captions are heavily skewed toward people and a few common phrases, so a small model learns to fall back on the most frequent pattern when it's unsure. Flickr30k will help a bit but COCO captions would probably help more if you can fit the training time, way more variety in subjects.
For the video part, if you haven't already, try sampling on scene changes instead of a fixed every-few-seconds interval. You get fewer near-duplicate captions on static shots and you stop missing short moments in fast-cut stuff. Even a simple frame-difference threshold works ok for a first pass.
Also might be worth trying the same decoder on top of a small pretrained encoder just as a comparison, not to replace yours, but it'd show you how much of the subject confusion is coming from the encoder vs the decoder. Cool MPS findings too, didn't know the conv patch embedding was that slow there.
2
u/Puzzleheaded-Tap-125 17d ago
Nice, I also want to start what steps fo you recommend I work in CV and use pretrained model but want to get into model arch. In depth what do you recommend .