TL;DR
This paper introduces CAD-Coder, an open-source Vision-Language Model (VLM) specifically fine-tuned to generate editable CAD code (CadQuery Python) directly from images. By leveraging a large, novel dataset and a LLaVA-based architecture, CAD-Coder significantly outperforms existing models in generating syntactically correct and geometrically accurate 3D CAD models from visual input, paving the way for more accessible and efficient engineering design.
What Problem Does This Paper Address?
Creating 3D CAD models is a cornerstone of engineering design, but it's a manual, time-consuming process that requires significant user expertise. While AI has shown promise in automating parts of this process, current methods often struggle with generating editable CAD code, generalizing to real-world images, and achieving high output accuracy. Many existing approaches either produce non-editable 3D shapes (like meshes) or rely on domain-specific languages (DSLs) that limit their scope and leverage of pre-trained knowledge. This leaves a gap for a model that can directly translate visual input into functional, editable CAD code using a widely-adopted scripting language.
Methods
The core of this work is CAD-Coder, an open-source VLM built upon the LLaVA 1.5 architecture. It utilizes a pre-trained vision encoder (CLIP-ViT-L-336px) and a pre-trained LLM (Vicuna-13B-v1.5). The model undergoes a two-stage training process:
- Stage 1: Pre-training for Feature Alignment: This stage aligns the image features from the vision encoder with the word embeddings of the LLM. A two-layer MLP is trained on a large image-caption dataset, keeping the vision encoder and LLM weights frozen.
- Stage 2: End-to-End GenCAD-Code Fine-tuning: This crucial stage fine-tunes the entire model (including the LLM weights) on the newly created GenCAD-Code dataset. This domain-specific fine-tuning is key to enabling the model to generate accurate CadQuery code.
The authors also introduce a novel metric for evaluating solid geometry similarity, IOUbest, which is argued to be more robust than previous methods like Chamfer distance.
Datasets
- GenCAD-Code: This is a newly introduced dataset created by the authors. It consists of over 163,000 pairs of rendered CAD images and their corresponding CadQuery Python code. This dataset is derived from the GenCAD dataset, with the CAD programs converted into CadQuery scripts.
- CC3M: Used in Stage 1 of training for feature alignment, this dataset consists of image-caption pairs.
Key Insights and Ideas
- Fine-tuning VLMs for Code Generation is Powerful: The success of CAD-Coder demonstrates that fine-tuning general-purpose VLMs on domain-specific code generation tasks can yield significant improvements over off-the-shelf models or models trained from scratch.
- Editable CAD Code is Key: Generating editable CAD code (like CadQuery scripts) is more valuable for engineering workflows than generating non-editable representations like meshes.
- Domain-Specific Fine-tuning Matters: The stark contrast in performance between CAD-Coder and a LLaVA 1.5 model trained on a generic VQA dataset highlights the critical importance of fine-tuning on the specific target domain (CAD code generation).
- Generalization to Real-World Images is Possible: Even though the model was primarily trained on rendered CAD images, it shows promising generalization capabilities when presented with images of real-world 3D-printed objects.
- Preserving Pre-trained Knowledge is Challenging: Experiments with different LLMs and learning rates suggest a trade-off between fine-tuning for the target task and preserving the LLM's original knowledge, particularly for unseen operations like filleting.
Key Results
- 100% Valid Syntax Rate (VSR): CAD-Coder achieved a perfect score for generating syntactically valid CadQuery code on the test set, a significant improvement over baselines.
- Highest Geometric Accuracy (IOUbest): CAD-Coder achieved the highest IOUbest score (0.675), outperforming state-of-the-art baselines (including GPT-4.5 and Qwen2.5-VL-72B) by a substantial margin (~60% better than the next-best open-source model).
- Promising Generalization: The model demonstrated the ability to generate reasonable CAD code from real-world object images, even though this was not part of its fine-tuning data.
- Limited Success with Unseen Operations: While the model showed some potential to generalize to unseen CAD operations (like filleting) with careful prompting and specific training variants, this generalization was not always robust.
Limitations and Future Work
- Real-World Image Accuracy: While CAD-Coder shows generalization to real-world images, its dimensional accuracy can be affected by perspective and lighting, suggesting a need for multi-view training or image augmentation.
- Unseen Operation Robustness: The ability to generalize to unseen CAD operations is currently prompt-dependent. Future work aims to develop strategies to better preserve pre-trained LLM knowledge during fine-tuning.
- Dataset Balance: The current dataset distribution is right-skewed, with fewer complex examples. Future work will focus on improving dataset balance.
- Longer Context LLMs: Adapting longer context pre-trained LLMs for CAD generation tasks with shorter context limits remains an area for further research.
- Exploring More Architectures: The authors plan to explore more model architectures to further improve robustness and generalizability.
Summary updated