--- license: mit task_categories: - object-detection - visual-question-answering language: - en tags: - visual-reasoning - grounding - counting - spatial-reasoning - maze - path-tracing - visual-primitives - chain-of-thought size_categories: - 100Kperson<|/ref|><|box|>[[480,201,720,850]]<|/box|>.\n3. **Conclusion**\nThe person is located at the specified coordinates.", "answer": "The person is located at [[480,201,720,850]].", "boxes": [[480, 201, 720, 850]], "points": [] } ``` ### SFT Counting ```json { "image": "images/000000000025.jpg", "question": "How many people are in this image?", "thinking": "1. **Analyzing the request**\nThe user asks me to count the person in this image.\n2. **Object grounding**\nI see 2 instance(s) of <|ref|>person<|/ref|><|box|>[[338,121,630,923],[634,154,888,945]]<|/box|>.\n3. **Conclusion**\nThere are 2 person in this image.", "count": 2, "boxes": [[338, 121, 630, 923], [634, 154, 888, 945]] } ``` ### Maze / Path (point primitives) ```json { "image": "images/maze_00001.png", "question": "Navigate from start to end in this maze.", "thinking": "... DFS exploration with <|point|>[[x,y]]<|/point|> waypoints ...", "answer": "...", "points": [[100, 200], [150, 250], [200, 300]] } ``` ## Visual Primitives ``` # Bounding box <|ref|>cat<|/ref|><|box|>[[x1,y1,x2,y2]]<|/box|> # Multiple boxes <|ref|>person<|/ref|><|box|>[[130,50,400,800],[500,60,750,790]]<|/box|> # Point sequence <|point|>[[100,200],[150,250],[200,300]]<|/point|> ``` ## Generation Scripts The `scripts/` folder contains all data generation code: | Script | Purpose | |--------|---------| | `prepare_all_data.py` | One-command pipeline (downloads COCO + generates all data) | | `generate_sft_grounding_data.py` | Grounding with negatives + diverse prompt templates | | `generate_maze_data.py` | Procedural maze generation with DFS solutions | | `generate_path_data.py` | Path tracing data generation | ### Regenerate from scratch ```bash # Full pipeline (downloads COCO 2017 val ~1GB) python scripts/prepare_all_data.py \ --output_dir data --coco_split val --coco_subset 5000 # Generate grounding with negatives python scripts/generate_sft_grounding_data.py \ --coco_jsonl data/pretrain/grounding.jsonl \ --image_root data/coco/val \ --output data/sft/grounding/sft_grounding.jsonl \ --neg_ratio 0.15 --max_samples 30000 ``` ## Source Images The JSONL files reference COCO 2017 images. Download them separately: - Train: [COCO 2017 Train](http://images.cocodataset.org/zips/train2017.zip) (18GB) - Val: [COCO 2017 Val](http://images.cocodataset.org/zips/val2017.zip) (1GB) For maze/spatial/path tasks, images are procedurally generated by the scripts. ## Related - [GitHub Repository](https://github.com/vra/Thinking-with-Visual-Primitives-pytorch) - Full training code and pipeline - [TVP-OPD-Qwen2VL-2B](https://huggingface.co/yunfengwang/TVP-OPD-Qwen2VL-2B) — Final distilled model - [TVP-SFTBox-Qwen2VL-2B](https://huggingface.co/yunfengwang/TVP-SFTBox-Qwen2VL-2B) — Box expert - [TVP-SFTPoint-Qwen2VL-2B](https://huggingface.co/yunfengwang/TVP-SFTPoint-Qwen2VL-2B) — Point expert - [TVP-Pretrain-Qwen2VL-2B](https://huggingface.co/yunfengwang/TVP-Pretrain-Qwen2VL-2B) — Pretrained base ## Citation ```bibtex @software{wang2026tvp_pytorch, title={Thinking with Visual Primitives — PyTorch Implementation}, author={Wang, Weishan}, url={https://github.com/vra/Thinking-with-Visual-Primitives-pytorch}, year={2026} } ``` ## License MIT