Run this model with HF Jobs

Run moonbox-dev/TRELLIS.2-4B-ONNX on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/moonbox-dev/TRELLIS.2-4B-ONNX. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/moonbox-dev/TRELLIS.2-4B-ONNX on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

TRELLIS.2-4B ONNX

ONNX builds of TRELLIS.2-4B, made by Moonbox for on-device use with ONNX Runtime (CPU, CUDA, DirectML). Each precision is one folder holding the graphs and a small Python pipeline.py that does the rest (image preprocessing, the sampling loop, mesh extraction); what the graphs take and return is under How to run.

Files

The last column is the benchmark against the original PyTorch model (details under How to run): how closely each mesh matches the original's, made from the same pictures and the same starting noise.

Precision File Size sha256 Benchmark
fp16 fp16/LICENSE-DINOv3.md 7.5 kB 25d122eb8f5b teacher forced (helmet / boar / pineapple): structure voxel IoU 0.984 / 0.996 / 0.986 (floor the same), latent SNR shape 22.6 / 22.3 / 22.9 dB (floor 22.5 / 22.0 / 22.7), texture 43.6 / 46.1 / 46.6 (floor 43.5 / 46.2 / 46.6), mesh F-score@0.005 0.955 / 0.987 / 0.9997 (floor the same); end to end 0.773 / 0.805 / 0.699 (the original in fp32: 0.773 / 0.805 / 0.709); 75-130 s per mesh from launch (CUDA)
fp16 fp16/LICENSE-TRELLIS2.txt 1.2 kB 5baa259ffd1a (the same build: numbers in its first row)
fp16 fp16/dinov3.onnx 0.6 MB 934ec6df1594 (the same build: numbers in its first row)
fp16 fp16/dinov3.onnx.data 1.21 GB ce45622f7671 (the same build: numbers in its first row)
fp16 fp16/pipeline.json 4.2 kB 222c359ab1ed (the same build: numbers in its first row)
fp16 fp16/pipeline.py 17.1 kB 11b5db7fd58a (the same build: numbers in its first row)
fp16 fp16/shape_dec_l0.onnx 0.1 MB 6d0661ed65f8 (the same build: numbers in its first row)
fp16 fp16/shape_dec_l0.onnx.data 520.4 MB ea31d19e4db3 (the same build: numbers in its first row)
fp16 fp16/shape_dec_l1.onnx 0.5 MB 2817877c5faf (the same build: numbers in its first row)
fp16 fp16/shape_dec_l1.onnx.data 364.6 MB f415d8a3a865 (the same build: numbers in its first row)
fp16 fp16/shape_dec_l2.onnx 0.3 MB b87c3f768904 (the same build: numbers in its first row)
fp16 fp16/shape_dec_l2.onnx.data 54.4 MB b5c8a34137de (the same build: numbers in its first row)
fp16 fp16/shape_dec_l3.onnx 0.2 MB 8247bb6a706f (the same build: numbers in its first row)
fp16 fp16/shape_dec_l3.onnx.data 9.0 MB c0215b1498b8 (the same build: numbers in its first row)
fp16 fp16/shape_dec_l4.onnx 30.7 kB 82b65879358b (the same build: numbers in its first row)
fp16 fp16/shape_dec_l4.onnx.data 0.2 MB 38b64517b469 (the same build: numbers in its first row)
fp16 fp16/shape_flow.onnx 2.0 MB cb2acb21aa5a (the same build: numbers in its first row)
fp16 fp16/shape_flow.onnx.data 2.62 GB 29f596437e7d (the same build: numbers in its first row)
fp16 fp16/ss_dec.onnx 37.9 kB 0d4a9a249e9d (the same build: numbers in its first row)
fp16 fp16/ss_dec.onnx.data 147.6 MB c092fd40b354 (the same build: numbers in its first row)
fp16 fp16/ss_flow.onnx 2.0 MB 964e7683a422 (the same build: numbers in its first row)
fp16 fp16/ss_flow.onnx.data 2.62 GB 9718ab87224c (the same build: numbers in its first row)
fp16 fp16/tex_dec_l0.onnx 0.1 MB 500a188f6b53 (the same build: numbers in its first row)
fp16 fp16/tex_dec_l0.onnx.data 520.3 MB 2f821e03819d (the same build: numbers in its first row)
fp16 fp16/tex_dec_l1.onnx 0.5 MB 47418f776b32 (the same build: numbers in its first row)
fp16 fp16/tex_dec_l1.onnx.data 364.6 MB a17b2605601a (the same build: numbers in its first row)
fp16 fp16/tex_dec_l2.onnx 0.3 MB 8e8465e10788 (the same build: numbers in its first row)
fp16 fp16/tex_dec_l2.onnx.data 54.4 MB 2d4f6c9f7d1c (the same build: numbers in its first row)
fp16 fp16/tex_dec_l3.onnx 0.2 MB 96868ef468bb (the same build: numbers in its first row)
fp16 fp16/tex_dec_l3.onnx.data 9.0 MB 67f546f1a00f (the same build: numbers in its first row)
fp16 fp16/tex_dec_l4.onnx 30.6 kB 028d6237bf96 (the same build: numbers in its first row)
fp16 fp16/tex_dec_l4.onnx.data 0.2 MB 2fad38c760c3 (the same build: numbers in its first row)
fp16 fp16/tex_flow.onnx 2.0 MB df9cdfc06d6f (the same build: numbers in its first row)
fp16 fp16/tex_flow.onnx.data 2.62 GB 5fd1ebc7da5e (the same build: numbers in its first row)
int8 int8/LICENSE-DINOv3.md 7.5 kB 25d122eb8f5b experimental: flows 8-bit: voxel IoU 0.976 / 0.994 / 0.983, latent SNR shape 18.1 / 18.6 / 19.5 dB, texture 29.6 / 33.2 / 34.4; end to end 0.735 / 0.835 / 0.761; 75-125 s per mesh
int8 int8/LICENSE-TRELLIS2.txt 1.2 kB 5baa259ffd1a (the same build: numbers in its first row)
int8 int8/dinov3.onnx 0.6 MB 934ec6df1594 (the same build: numbers in its first row)
int8 int8/dinov3.onnx.data 1.21 GB ce45622f7671 (the same build: numbers in its first row)
int8 int8/pipeline.json 4.2 kB 222c359ab1ed (the same build: numbers in its first row)
int8 int8/pipeline.py 17.1 kB 11b5db7fd58a (the same build: numbers in its first row)
int8 int8/shape_dec_l0.onnx 0.1 MB 6d0661ed65f8 (the same build: numbers in its first row)
int8 int8/shape_dec_l0.onnx.data 520.4 MB ea31d19e4db3 (the same build: numbers in its first row)
int8 int8/shape_dec_l1.onnx 0.5 MB 2817877c5faf (the same build: numbers in its first row)
int8 int8/shape_dec_l1.onnx.data 364.6 MB f415d8a3a865 (the same build: numbers in its first row)
int8 int8/shape_dec_l2.onnx 0.3 MB b87c3f768904 (the same build: numbers in its first row)
int8 int8/shape_dec_l2.onnx.data 54.4 MB b5c8a34137de (the same build: numbers in its first row)
int8 int8/shape_dec_l3.onnx 0.2 MB 8247bb6a706f (the same build: numbers in its first row)
int8 int8/shape_dec_l3.onnx.data 9.0 MB c0215b1498b8 (the same build: numbers in its first row)
int8 int8/shape_dec_l4.onnx 30.7 kB 82b65879358b (the same build: numbers in its first row)
int8 int8/shape_dec_l4.onnx.data 0.2 MB 38b64517b469 (the same build: numbers in its first row)
int8 int8/shape_flow.onnx 2.1 MB b8610f47258c (the same build: numbers in its first row)
int8 int8/shape_flow.onnx.data 1.38 GB 18bf5b7444c5 (the same build: numbers in its first row)
int8 int8/ss_dec.onnx 37.9 kB 0d4a9a249e9d (the same build: numbers in its first row)
int8 int8/ss_dec.onnx.data 147.6 MB c092fd40b354 (the same build: numbers in its first row)
int8 int8/ss_flow.onnx 2.1 MB 04d70c404426 (the same build: numbers in its first row)
int8 int8/ss_flow.onnx.data 1.38 GB cd009c010cd0 (the same build: numbers in its first row)
int8 int8/tex_dec_l0.onnx 0.1 MB 500a188f6b53 (the same build: numbers in its first row)
int8 int8/tex_dec_l0.onnx.data 520.3 MB 2f821e03819d (the same build: numbers in its first row)
int8 int8/tex_dec_l1.onnx 0.5 MB 47418f776b32 (the same build: numbers in its first row)
int8 int8/tex_dec_l1.onnx.data 364.6 MB a17b2605601a (the same build: numbers in its first row)
int8 int8/tex_dec_l2.onnx 0.3 MB 8e8465e10788 (the same build: numbers in its first row)
int8 int8/tex_dec_l2.onnx.data 54.4 MB 2d4f6c9f7d1c (the same build: numbers in its first row)
int8 int8/tex_dec_l3.onnx 0.2 MB 96868ef468bb (the same build: numbers in its first row)
int8 int8/tex_dec_l3.onnx.data 9.0 MB 67f546f1a00f (the same build: numbers in its first row)
int8 int8/tex_dec_l4.onnx 30.6 kB 028d6237bf96 (the same build: numbers in its first row)
int8 int8/tex_dec_l4.onnx.data 0.2 MB 2fad38c760c3 (the same build: numbers in its first row)
int8 int8/tex_flow.onnx 2.1 MB dfb8b97fbe42 (the same build: numbers in its first row)
int8 int8/tex_flow.onnx.data 1.38 GB c7d6264999fc (the same build: numbers in its first row)

How to run

TRELLIS.2-4B (Microsoft: one picture of an object to a 3D mesh with colours) as ONNX graphs plus pipeline.py, a numpy runtime that reproduces the official Trellis2ImageTo3DPipeline (github.com/microsoft/TRELLIS.2) in its 512 mode: the shape is decoded on a 512^3 grid.

What runs. TRELLIS.2 works on sparse voxels:

  • Image features: DINOv3 ViT-L/16 encodes the picture (512 x 512) into 1,029 feature vectors.
  • Structure: a flow transformer (1.3B) samples a 16^3 x 8 latent, and a convolutional decoder turns it into an occupancy grid, pooled to 32^3. Its occupied voxels (typically 2-5 thousand) are the structure.
  • Shape latent: a second flow transformer (1.3B) samples 32 latent features per voxel.
  • Texture latent: a third (1.3B) samples 32 more per voxel, conditioned on the shape latent.
  • Decoding: the shape decoder subdivides the voxels four times (32^3 to 512^3; each step predicts which of a voxel's 8 children exist) and gives every final voxel a dual vertex, which edges the surface crosses and how to split each quad: the mesh. The texture decoder follows the same subdivisions and gives every voxel its PBR attributes (base colour, metallic, roughness, alpha).

The weights come from three repositories, as the official pipeline loads them:

  • microsoft/TRELLIS.2-4B: the three flows (the 512 ones) and the shape / texture decoders;
  • microsoft/TRELLIS-image-large: the structure decoder;
  • facebook/dinov3-vitl16-pretrain-lvd1689m: the image encoder.

Not included:

  • the 1024_cascade mode (the official default: a second shape pass at 1024^3);
  • the background remover (briaai/RMBG-2.0): give pipeline.py a picture with the object already cut out (RGBA);
  • the original's mesh post-processing and baking: CuMesh hole filling, remeshing and decimation, and the UV texture bake (nvdiffrast). The mesh is the decoder's own, with the base colour per vertex (save_mesh), and the PBR voxel attributes are returned too.

The graphs. ONNX has no sparse operations, so pipeline.py builds index tables from the voxel coordinates in numpy and the graphs use them:

  • a submanifold 3x3x3 convolution (FlexGEMM in the original) is 27 gathers of neighbour features times the kernel slices, summed in fp32;
  • each decoder runs as five graphs, one per resolution; between them numpy turns the predicted subdivisions into the next level's voxels and gather indices;
  • the flows' attention is full attention over the voxels (com.microsoft MultiHeadAttention); the 3D rotary position phases are graph inputs.
Graph Inputs Output
dinov3.onnx pixel_values [1, 3, 512, 512] [1, 1029, 1024] (fp32, as the original)
ss_flow.onnx x [B, 8, 16, 16, 16], t [B] (1000 t), cond [B, 1029, 1024], rope_cos / rope_sin [4096, 64] velocity
ss_dec.onnx z [1, 8, 16, 16, 16] occupancy logits [1, 1, 64, 64, 64]
shape_flow.onnx x [N, 32], t [1], cond, rope_cos / rope_sin [N, 64] velocity [N, 32]
tex_flow.onnx as shape_flow + concat [N, 32] (the normalised shape latent) velocity [N, 32]
shape_dec_l0 ... l4 level 0: latent [N, 32], nbr [N, 27]; then h_prev, skip_prev, gidx, nbr features for the next level (+ subdivision logits [N, 8]); level 4: [N, 7]
tex_dec_l0 ... l4 the same level 4: [N, 6]
import sys
sys.path.insert(0, "fp16")
import pipeline
from PIL import Image
p = pipeline.Trellis2("fp16", "cuda")
verts, faces, colours, (voxels, attrs) = p(Image.open("object.png"), seed=42)   # RGBA picture
pipeline.save_mesh("object.glb", verts, faces, colours)                          # y-up, vertex colours

Or python fp16/pipeline.py object.png object.glb --seed 42. It needs numpy, Pillow and onnxruntime-gpu; trimesh to write GLB (PLY without it); torch (CPU) only to draw the original's noise for a seed (numpy's otherwise).

Ported as the original behaves.

  • Preprocessing: the original's crop around the alpha mask, LANCZOS resizes and normalisation.
  • Sampler: 12 Euler steps per stage with pipeline.json's time rescaling, guidance strengths, guidance intervals and CFG rescale (the structure latent's standard deviation unbiased, the sparse latents' as their tensor class computes it).
  • Noise: with torch installed, a seed draws the original's noise (torch's CPU generator, in the original's order), so the first stage starts from exactly the original's latent.
  • Mesh: O-Voxel's flexible_dual_grid_to_mesh (a hashmap lookup of each flagged edge's four voxels, quads split on the larger product of split weights) in numpy.
  • Graph optimization: sessions use the basic level and are loaded one at a time; the CUDA memory arena grows only by what each graph asks for.

Running it.

  • Memory: about 11 GB of system memory at the peak on Windows (GPU allocations count toward it); the largest graphs are the 256^3 decoder level and the flows (2.6 GB each).
  • Time: on an RTX 3080 Laptop GPU, 75-130 s per mesh with fp16/ or int8/, loading each graph as its stage starts: features 2-3 s, structure 23 s, shape 15-22 s, texture 11-15 s, decoding 22-50 s. More voxels take longer. The original (PyTorch: FlexGEMM, SDPA attention) takes about 30-45 s of inference here, models already loaded: structure 13 s, shape 8-14 s, texture 4-8 s, decoding 2-7 s.
  • cuDNN log lines: ONNX Runtime may print cuDNN "No execution plans support the graph" errors while it picks an algorithm for the structure decoder's 3-D convolutions. They are harmless.

Precisions.

  • fp16/ (11.1 GB): the flows and decoders in fp16, as the original runs them; the flows' residual stream, the LayerNorms, the embedders and the convolutions' sums in fp32 (the original's flows are bf16; fp16 has room: their residual stream peaks at 9e3). DINOv3 stays fp32, as the original runs it.
  • int8/ (7.4 GB), experimental: the three flows' MatMuls 8-bit MatMulNBits (block 32, 99.9 % of their weights); the rest as fp16/. Below the pass mark on the latent stages (below), though its shapes end to end are as close to the original's as the original's own fp32 run is.
  • No int4: tried (the flows 4-bit) and far below the pass mark (latent SNR 4-11 dB; on the pineapple the structure keeps 34 % of the voxels). No bf16: fp16 passes.

Benchmark.

  • Pictures: three of the official repository's example images (assets/example_image, sorted order 9, 10, 20: a helmet, a boar, a pineapple), seed 42.
  • Original: Trellis2ImageTo3DPipeline (GitHub @ 75fbf01), 512 mode, run on Windows stage by stage with every intermediate saved: its flows in bf16 and decoders in fp16, as it runs; FlexGEMM (its sparse convolutions, built for Windows); attention through PyTorch SDPA instead of flash-attn (no Windows build); O-Voxel's mesh extraction with its two CUDA hashmap kernels replaced by an equivalent lookup (O-Voxel doesn't build on Windows).
  • Teacher forced: the sampler is chaotic: the original in fp32 from the same noise keeps 98.4-99.6 % of its structure voxels, and every later stage diverges from there. So each stage is fed the original's own inputs (features, noise, voxels, latents) and scored against the original's output:
    • structure: latent SNR and voxel IoU;
    • shape and texture latents: SNR;
    • mesh: F-score at 0.005 (0.5 % of the shape's extent) on 200k surface samples, and the IoU of the 512^3 voxels;
    • texture attributes: SNR on the shared voxels.
  • Pass mark: each stage at least as close as the original's own fp32 run of that stage, on the same inputs (the mean over the pictures).
structure: SNR / voxel IoU shape latent: SNR texture latent: SNR mesh: F-score / 512^3 voxel IoU texture: attribute SNR end to end: F-score
original in fp32 (the floor) 18.9 / 28.2 / 25.0 dB, 0.984 / 0.996 / 0.986 22.5 / 22.0 / 22.7 dB 43.5 / 46.2 / 46.6 dB 0.955 / 0.987 / 0.9997, 0.9985 / 0.9990 / 0.9989 62.4 / 64.6 / 66.1 dB 0.773 / 0.805 / 0.709
fp16/ 18.8 / 28.2 / 25.5 dB, 0.984 / 0.996 / 0.986 22.6 / 22.3 / 22.9 dB 43.6 / 46.1 / 46.6 dB 0.955 / 0.987 / 0.9997, 0.9986 / 0.9992 / 0.9991 63.2 / 66.3 / 66.9 dB 0.773 / 0.805 / 0.699
int8/ (experimental) 16.4 / 25.4 / 24.0 dB, 0.976 / 0.994 / 0.983 18.1 / 18.6 / 19.5 dB 29.6 / 33.2 / 34.4 dB (the same decoders as fp16/) (the same) 0.735 / 0.835 / 0.761
int4 (not published) 4.3 / 6.8 / -0.5 dB, 0.837 / 0.888 / 0.343 3.9 / 4.8 / 6.0 dB 8.8 / 10.9 / 14.2 dB (the same) (the same) 0.533 / 0.634 / 0.157

Columns are helmet / boar / pineapple.

  • The mesh and texture columns: the decoders are the same fp16 graphs in every build, fed the original's latents. Their meshes match the original's as closely as the original's own fp32 decoders do.
  • End to end: from the picture with the original's noise. The structure keeps about 98.5 % of the original's voxels, so the later noise falls on different voxels and the details diverge, as they do between the original's own bf16 and fp32 runs (the floor row: the original fully in fp32 from the picture). Compared that way, a score near the floor is as close as the original gets to itself; the shapes are the same objects.

Before the benchmark each graph was checked against its PyTorch module on real inputs (cosine): DINOv3 1.0; structure flow 0.99998 (against the bf16 original, which itself is at 0.99984 of its fp32 run); structure decoder 0.99999997; shape flow 0.99996; texture flow 0.99997; each decoder level 0.9999998 or closer. The decoders' level chains against the original FlexGEMM decoders: the texture decoder gives the same voxels at every level; in the shape decoder one of 97,280 subdivision logits sat on the fp16 rounding boundary and flipped (77 of 1.77 million final voxels differ, as the original's own fp32 run differs too).

License. TRELLIS.2 (code and weights) is MIT (LICENSE-TRELLIS2.txt). The image encoder is DINOv3, under the DINOv3 License (LICENSE-DINOv3.md): it allows use and redistribution, and anyone redistributing it must pass the licence on with it.

How these were made

From TRELLIS.2-4B at revision af44b45f2e. The graphs were exported from the original PyTorch modules with torch.onnx (opset 17 / 18) and checked against them. Weight-only quantization: int8 is a per-output-channel int8 weight behind DequantizeLinear, int4 is ONNX Runtime's MatMulNBits (block 32). Each card above says which precision every graph uses. Every precision was benchmarked against the original before upload (the pass mark is under How to run), and the sha256 column above is what the files must hash to.

License

MIT (TRELLIS.2) + DINOv3 License (image encoder). These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.


Original model card

TRELLIS.2: Native and Compact Structured Latents for 3D Generation

Model Name: TRELLIS.2-4B

Paper: https://arxiv.org/abs/2512.14692

Repository: https://github.com/microsoft/TRELLIS.2

Project Page: https://microsoft.github.io/trellis.2

Introduction

TRELLIS.2 is a state-of-the-art large 3D generative model designed for high-fidelity image-to-3D generation. It leverages a novel "field-free" sparse voxel structure termed O-Voxel and a large-scale flow-matching transformer (4 Billion parameters).

Unlike previous methods that rely on iso-surface fields (e.g., SDF, Flexicubes) which struggle with open surfaces or non-manifold geometry, TRELLIS can reconstruct and generate arbitrary 3D assets with complex topologies, sharp features, and full Physical-Based Rendering (PBR) materials—including transparency/translucency.

Model Details

  • Developed by: Jianfeng Xiang, Xiaoxue Chen, Sicheng Xu, Ruicheng Wang, Zelong Lv, Yu Deng, Hongyuan Zhu, Yue Dong, Hao Zhao, Nicholas Jing Yuan, Jiaolong Yang
  • Model Type: Flow-Matching Transformers with Sparse Voxel based 3D VAE
  • Parameters: 4 Billion
  • Input: Single Image
  • Output: 3D Asset (Mesh with PBR Materials)
  • Resolution: Varies from 512³ to 1536³ (Voxel Grid Resolution)

Key Features

  • O-Voxel Representation: An omni-voxel structure that encodes both geometry and appearance. It supports:
    • Arbitrary Topology: Handles open surfaces, non-manifold geometry, and fully-enclosed structures without lossy conversion.
    • Rich Appearance: Captures PBR attributes (including opacity for translucent surfaces) aligned with geometry.
    • Efficiency: Instant optimization-free bidirectional conversion between meshes and O-Voxels (ms to seconds).
  • High-Resolution Generation: The model is trained to generate fully textured assets at up to 1536³ resolution.
  • High-Fidelity while Compact Latent Space: Utilizes a Sparse 3D VAE with 16× spatial downsampling, encoding a 1024³ asset into only ~9.6K latent tokens with negligible perceptual degradation.
  • Shape-conditioned Texture Generation: Generates textures for input 3D meshes and reference images.
  • State-of-the-Art Speed: Inference is highly efficient; see table below.

Inference Speed (NVIDIA H100 GPU)

Resolution Time
512³ ~3 seconds
1024³ ~17 seconds
1536³ ~60 seconds

Requirements

  • System: The model is currently tested only on Linux.
  • Hardware: An NVIDIA GPU with at least 24GB of memory is necessary. The code has been verified on NVIDIA A100 and H100 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain packages. Recommended version is 12.4.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

Known Limitations

  • Geometric Artifacts (Small Holes): While O-Voxels handle complex topology well, the generated raw meshes may occasionally contain small holes or minor topological discontinuities. For applications requiring strictly watertight geometry (e.g., 3D printing), we provide accompanying mesh post-processing scripts, such as hole-filling algorithms.
  • Base Model w/o Alignment: TRELLIS.2-4B is a pre-trained foundation model. It has not been aligned with human preferences (e.g., via RLHF) or fine-tuned for specific aesthetic standards. Consequently, the outputs reflect the distribution of the training data and may vary in style; users may need to experiment with inputs to achieve the desired artistic result.

We are actively working on improving the model and addressing these limitations.

Usage

Note: Please refer to the official GitHub Repository for installation instructions and dependencies.

import os
os.environ['OPENCV_IO_ENABLE_OPENEXR'] = '1'
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"  # Can save GPU memory
import cv2
import imageio
from PIL import Image
import torch
from trellis2.pipelines import Trellis2ImageTo3DPipeline
from trellis2.utils import render_utils
from trellis2.renderers import EnvMap
import o_voxel

# 1. Setup Environment Map
envmap = EnvMap(torch.tensor(
    cv2.cvtColor(cv2.imread('assets/hdri/forest.exr', cv2.IMREAD_UNCHANGED), cv2.COLOR_BGR2RGB),
    dtype=torch.float32, device='cuda'
))

# 2. Load Pipeline
pipeline = Trellis2ImageTo3DPipeline.from_pretrained("microsoft/TRELLIS.2-4B")
pipeline.cuda()

# 3. Load Image & Run
image = Image.open("assets/example_image/T.png")
mesh = pipeline.run(image)[0]
mesh.simplify(16777216) # nvdiffrast limit

# 4. Render Video
video = render_utils.make_pbr_vis_frames(render_utils.render_video(mesh, envmap=envmap))
imageio.mimsave("sample.mp4", video, fps=15)

# 5. Export to GLB
glb = o_voxel.postprocess.to_glb(
    vertices            =   mesh.vertices,
    faces               =   mesh.faces,
    attr_volume         =   mesh.attrs,
    coords              =   mesh.coords,
    attr_layout         =   mesh.layout,
    voxel_size          =   mesh.voxel_size,
    aabb                =   [[-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]],
    decimation_target   =   1000000,
    texture_size        =   4096,
    remesh              =   True,
    remesh_band         =   1,
    remesh_project      =   0,
    verbose             =   True
)
glb.export("sample.glb", extension_webp=True)

Citation

If you find this model useful for your research, please cite our work:

@article{
    xiang2025trellis2,
    title={Native and Compact Structured Latents for 3D Generation},
    author={Xiang, Jianfeng and Chen, Xiaoxue and Xu, Sicheng and Wang, Ruicheng and Lv, Zelong and Deng, Yu and Zhu, Hongyuan and Dong, Yue and Zhao, Hao and Yuan, Nicholas Jing and Yang, Jiaolong},
    journal={Tech report},
    year={2025}
}

License

This model is released under the MIT License. The code and dataset are publicly released to facilitate reproduction and further research.

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

Model tree for moonbox-dev/TRELLIS.2-4B-ONNX

Quantized
(6)
this model

Paper for moonbox-dev/TRELLIS.2-4B-ONNX