Skip to content

feat: Port SAM 3D Objects (sam3d_objects) with mesh and Gaussian output #2381

Closed

Description

@inureyes

Part of #2382

Problem / Background

Port SAM 3D Objects (sam3d_objects, Meta): reconstruct a 3D object from one image and an object mask, returning pose, a sparse voxel latent, a textured triangle mesh and 3D Gaussians. mlxcel has no geometry output of any kind, so this issue adds the mesh and Gaussian output surface on top of the dense-prediction infrastructure, plus the model itself. It conditions on DINOv2 features and, when no point map is supplied, estimates one with MoGe-3, so it depends on both of those issues.

Upstream reference

  • Model directory: mlx_vlm/models/sam3d_objects (README). PR: feat: SAM 3D Objects for MLX Neywa-Labs/mlx-vlm#2282.
  • Bundle: mlx-community/sam-3d-objects-bf16 (weights plus metadata, loaded from a local directory by Pipeline.from_pretrained).
  • Stages (README code map): processing.py builds object crops and full-image views, normalizes the point map (+X left, +Y up, +Z forward, NaN invalid) and decodes pose; depth.py estimates a point map through the shared MoGe-3 model when the bundle has a depth model and estimate_depth is on; vision.py wraps the shared DINOv2 (ViT-L with registers, also importing its Attention and Mlp) and embeds point maps; flow.py StructureFlow (sparse structure and pose, ss) and LatentFlow (sparse latent features, slat); pipeline.py integrates both stages (Pipeline._run); decoders.py occupancy, Gaussian and mesh heads; mesh.py plus mesh_tables.py FlexiCubes triangle extraction; sparse.py grid topology, sparse conv, pooling and window attention.
  • Sampling defaults in config.py#L80-L84: ss_steps 25, slat_steps 25, ss_guidance 7.0, slat_guidance 1.0.
  • CLI generate.py#L114-L195: --image, --mask (alpha used when omitted), --pointmap (safetensors with points), --seed 42, --ss-steps, --slat-steps, --formats gaussian|gaussian_4|mesh (default gaussian and mesh), --no-depth, --output DIR; writes result.safetensors and PLY/OBJ. write_gaussians converts scales to log scale and opacities to logits; write_obj writes RGB vertex colors and 1-based faces. Geometry stays in object-local coordinates; pose (WXYZ quaternion, rotation matrix, translation, scale) is returned separately.

Current Behavior

Proposed Solution

  • Output surface in src/vision/dense/geometry_io.rs: write_obj(path, &Mesh) (vertices, zero-based faces converted to 1-based, v x y z r g b from the first three of six vertex-color channels) and write_gaussian_ply(path, &Gaussians) (binary little-endian f32 PLY with fields x y z nx ny nz f_dc_0 f_dc_1 f_dc_2 opacity scale_0 scale_1 scale_2 rot_0 rot_1 rot_2 rot_3, normals zero, opacity clipped to [1e-7, 1 - 1e-7] then logit, scales as log), matching upstream write_obj / write_gaussians field order. Mesh { vertices: (N, 3), faces: (F, 3) u32, vertex_colors: (N, 6) }, Gaussians { positions, sh_dc, scales, rotations, opacities }. Add OutputKind::Mesh to the registry and extend DenseOutput from feat: Add dense-prediction output surface: mlxcel predict, map and keypoint files #2349 with meshes: Vec<(String, Mesh)> and gaussians: Vec<(String, Gaussians)> so the writer emits mesh.obj, gaussian.ply and gaussian_4.ply.
  • CLI: add --mask <PATH> and --pointmap <PATH> to mlxcel predict (used only by families that declare them; others reject them). Options through --opts: seed, ss_steps, slat_steps, formats, estimate_depth (default true).
  • Model in src/vision/dense/sam3d_objects/ (config.rs, bundle.rs, processing.rs, vision.rs, flow.rs, sparse.rs, decoders.rs, mesh.rs, mesh_tables.rs, pipeline.rs, mod.rs), registered as sam3d_objects. Conditioners reuse Dinov2 (Attention, Mlp) from feat: Port DINOv2 backbone (dinov2, dinov2_with_registers) for dense models #2350; depth estimation calls Moge3::estimate from feat: Port MoGe-3 (moge3) monocular geometry: point, depth, normal maps #2355 and converts its camera axes while preserving metric scale.
  • result.safetensors holds pose.*, coords, latents, pointmap_conditioned; meta.json records seeds, steps and whether a point map conditioned the run.

Scope

In scope: mesh and Gaussian writers, OutputKind::Mesh, the --mask / --pointmap flags, the full model, docs (docs/dense-prediction.md geometry section, docs/supported-models.md).

Out of scope: JSONL batch mode and astream (follow-up), scene placement by applying pose to exported geometry, conversion tooling (convert.py), a server endpoint.

Implementation Notes

Acceptance Criteria

  • mlxcel predict -m models/sam-3d-objects-bf16 --image chair.png --mask chair_mask.png -o out/ writes mesh.obj, gaussian.ply, result.safetensors and meta.json; the OBJ opens in a standard viewer and the PLY loads in a Gaussian-splat viewer.
  • RGBA input without --mask uses the alpha channel; --opts '{"estimate_depth":false}' sets pointmap_conditioned false.
  • Parity with seed 42 and default steps: identical occupancy coords to upstream, latents relative RMS below 1e-2, mesh vertex count within 1% and Chamfer distance below 1e-3 of the object scale.
  • Unit tests: OBJ writer emits 1-based faces and RGB colors; PLY writer round-trips log-scale and logit fields against upstream write_gaussians on a 3-point fixture; mask validation; FlexiCubes extraction on a sphere SDF fixture; each fails on current main.
  • mlxcel arch lists sam3d_objects with output kind mesh; docs/supported-models.md updated.

Verification

cargo build --release --features metal,accelerate
cargo test --workspace --profile test-fast --features metal,accelerate sam3d_objects
cargo test --workspace --profile test-fast --features metal,accelerate geometry_io
cargo test --workspace --profile test-fast --features metal,accelerate
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
./target/release/mlxcel predict -m models/sam-3d-objects-bf16 --image /path/to/chair.png --mask /path/to/chair_mask.png -o /tmp/sam3d-out

Dependencies

Blocked by #2349 (dense output surface), #2350 (DINOv2) and #2355 (MoGe-3 depth estimation). Re-scopes the 3D-geometry output entry of #524.

Activity

  1. added
    type:enhancement
    priority:low
    status:blocked
    area:models
    modeltype:vlm
    modelsize:medium
    on Oct 16, 2026
  2. added
    status:in-progress
    and removed
    status:blocked
    on Oct 23, 2026
  3. added
    status:review
    status:done
    and removed
    status:in-progress
    status:review
    on Oct 23, 2026
  4. added a commit that references this issue on Oct 25, 2026
    5730298
  5. added this to the 0.8 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:modelsmodelsize:mediummodeltype:vlmpriority:lowstatus:donetype:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions