1from transformers import AutoProcessor, AutoModelForVision2Seq, BitsAndBytesConfig
2from huggingface_hub import hf_hub_download
3from PIL import Image
4import torch
5
6# Download adapter
7adapter_path = hf_hub_download(
8 repo_id="qq456cvb/img2cad",
9 filename="llamaft/chair/adapter_model.safetensors"
10)
11adapter_dir = str(Path(adapter_path).parent)
12
13# Load base model
14model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
15bnb_config = BitsAndBytesConfig(
16 load_in_4bit=True,
17 bnb_4bit_use_double_quant=True,
18 bnb_4bit_quant_type="nf4",
19 bnb_4bit_compute_dtype=torch.bfloat16
20)
21
22model = AutoModelForVision2Seq.from_pretrained(
23 model_id,
24 device_map="auto",
25 torch_dtype=torch.bfloat16,
26 quantization_config=bnb_config
27)
28processor = AutoProcessor.from_pretrained(model_id)
29
30# Load adapter
31model.load_adapter(adapter_dir)
32model.eval()
33
34# Inference
35image = Image.open("your_image.png").convert("RGB")
36# ... see full inference code in the repository
1from omegaconf import OmegaConf
2from huggingface_hub import hf_hub_download
3import torch
4import numpy as np
5
6# Download checkpoint and config
7ckpt_path = hf_hub_download(
8 repo_id="qq456cvb/img2cad",
9 filename="trassembler/chair/last.ckpt"
10)
11config_path = hf_hub_download(
12 repo_id="qq456cvb/img2cad",
13 filename="trassembler/chair/config.yaml"
14)
15
16# Load model (requires Img2CAD repository)
17from TrAssembler.model import GMFlowModel
18
19config = OmegaConf.load(config_path)
20model = GMFlowModel.load_from_checkpoint(
21 ckpt_path,
22 args=config,
23 embed_dim=config.network.embed_dim,
24 num_heads=config.network.num_heads,
25 dropout=config.network.dropout,
26 bias=True,
27 scaling_factor=1.,
28 args_range=np.array([-1., 1.])
29).cuda().eval()
30
31# Generate CAD parameters
32# pred_args = model.sample(batch)
1@inproceedings{you2025img2cad,
2 title={Img2cad: Reverse engineering 3d cad models from images through vlm-assisted conditional factorization},
3 author={You, Yang and Uy, Mikaela Angelina and Han, Jiaqi and Thomas, Rahul and Zhang, Haotong and Du, Yi and Chen, Hansheng and Engelmann, Francis and You, Suya and Guibas, Leonidas},
4 booktitle={Proceedings of the SIGGRAPH Asia 2025 Conference Papers},
5 pages={1--12},
6 year={2025}
7}
This project is released under the MIT License.