CADFit β€” Loop classifier (model_mlp_med.pt)

This repo hosts the trained loop-filtering model used by CADFit, our framework for precise mesh-to-CAD program generation via hybrid optimization (ICML 2026).

What CADFit does

CADFit recovers complex, editable CAD construction sequences from watertight meshes by incrementally fitting and validating parametric operations using geometric feedback. Instead of predicting a program in one forward pass, CADFit formulates reconstruction as an explicit IoU-driven optimization over executable CAD programs, supporting a rich operator set (extrusions, revolutions, fillets, chamfers) composed with Boolean union and cut.

Pipeline:

  1. Slice the mesh at axis-aligned and detected planar slabs to extract 2D contour loops (extract_planar_contours.py, extract_sketches.py).
  2. Filter loops β€” this model scores every candidate loop and discards ones unlikely to be useful sketch primitives.
  3. Analyze translations and revolves β€” for each surviving loop, find the extrusion height ranges and the symmetry axes that align with the underlying CAD program.
  4. Greedy reconstruction β€” at each step add the candidate operation that yields the largest IoU gain against the input mesh, accepting/rejecting via CadQuery kernel evaluation. Continue until residual volume falls below tolerance.
  5. Iterative residual refinement β€” reconstruct positive and negative residuals with the same pipeline and compose via Boolean union/cut.

The result is a clean, editable, executable CAD program (Python via CadQuery).

The classifier

model_mlp_med.pt is a 3-layer MLP that takes:

  • A 4 Γ— 1024-d DINOv2 ViT-L/14 embedding of 4 rendered views per loop (isometric mesh, isometric mesh + loop overlay, face-on mesh, face-on mesh + loop overlay), 224 Γ— 224 px each.
  • A 17-d hand-crafted geometric descriptor (loop area, perimeter, point count, bbox extents, plane origin, plane normal, axis-alignment, …).

Total input: 4 Γ— 1024 + 17 = 4113-d. Standardized with (mu, sd) from normalization.npz, then passed through:

Linear(4113 β†’ h₁) β†’ GELU β†’ Dropout
Linear(h₁ β†’ hβ‚‚)  β†’ GELU β†’ Dropout
Linear(hβ‚‚ β†’ 1)   β†’ sigmoid

(h₁, hβ‚‚, and dropout p are stored in ckpt["arch"].)

The output sigmoid probability β‰₯ threshold (default 0.425, also stored in the checkpoint) is the keep decision.

In CADFit the filter slots in between loop extraction and translation/revolve analysis, shrinking the candidate search space and keeping the greedy reconstruction focused on loops that have a chance of corresponding to a real CAD sketch primitive.

Typical impact

  • Drops roughly half of the raw extracted loops.
  • Reduces translation/revolve analysis runtime ~2Γ—.
  • Improves greedy reconstruction quality (slightly higher mean IoU on ABC-Easy / Medium / Hard).

How to use

From CADFit (recommended)

# Install CADFit and the optional filter dependencies
pip install -r requirements.txt
pip install torch pyvista Pillow huggingface-hub

# Headless Linux only β€” install Xvfb for off-screen PyVista rendering:
sudo apt-get install xvfb

# Run the pipeline with the filter enabled.
# Model weights auto-download from this repo on first call.
python run_pipeline.py mesh_folder/ --output-folder runs/ --filter-sketches

Stand-alone

from huggingface_hub import hf_hub_download
from filter_loops import filter_jsons_inplace

# Filter a loops_split.json in place; weights cached after first call.
filter_jsons_inplace(
    stl_path="mesh.stl",
    json_paths=["loops_split.json"],
    threshold=0.425,
)

Direct download

from huggingface_hub import hf_hub_download

mlp = hf_hub_download("ghadinehme/CADFit", "model_mlp_med.pt")
norm = hf_hub_download("ghadinehme/CADFit", "normalization.npz")

Citation

@article{nehme2026cadfit,
  title   = {CADFit: Precise Mesh-to-CAD Program Generation with Hybrid Optimization},
  author  = {Nehme, Ghadi and Whalen, Eamon and Ahmed, Faez},
  journal = {arXiv preprint arXiv:2605.01171},
  year    = {2026}
}

License

Released under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license. Free for academic and research use; commercial licensing inquiries to ghadi@mit.edu.

Contact

Questions, feedback, or collaboration: ghadi@mit.edu.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Paper for ghadinehme/CADFit