Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Gaur2210/TRELLIS

 
 

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXiv Project Page

TRELLIS is a large 3D asset generation model. It takes in text or image prompts and generates high-quality 3D assets in various formats, such as Radiance Fields, 3D Gaussians, and meshes. The cornerstone of TRELLIS is a unified Structured LATent (SLAT) representation that allows decoding to different output formats and Rectified Flow Transformers tailored for SLAT as the powerful backbones. We provide large-scale pre-trained models with up to 2 billion parameters on a large 3D asset dataset of 500K diverse objects. TRELLIS significantly surpasses existing methods, including recent ones at similar scales, and showcases flexible output format selection and local 3D editing capabilities which were not offered by previous models.

🤔 Why This Repository

Many people don't have the resources to run TRELLIS on their local systems, so they use Kaggle or Colab. This repository is a modified version for Kaggle or Colab implementation. A sample FastAPI is implemented in main.py, which users can customize in whatever way they want. Additionally, test.js contains a sample POST request for testing purposes.

🚀 Steps to Run in Kaggle or Colab

Clone the Repository

!git clone --recurse-submodules https://github.com/RameshBabuAsh/TRELLIS.git

Give Permissions and Run setup.sh

Kaggle

!chmod +x /kaggle/working/TRELLIS/setup.sh
!/kaggle/working/TRELLIS/setup.sh

Colab

!chmod +x /content/TRELLIS/setup.sh
!/content/TRELLIS/setup.sh

Run first_run.py

Kaggle

!python /kaggle/working/TRELLIS/first_run.py

Colab

!python /content/TRELLIS/first_run.py

Start Writing Sample Code

import os
os.chdir('/content/TRELLIS') # os.chdir('/kaggle/working/TRELLIS')

# Set environment variables
os.environ['ATTN_BACKEND'] = 'xformers'   # Can be 'flash-attn' or 'xformers', default is 'flash-attn'
os.environ['SPARSE_ATTN_BACKEND'] = 'xformers'
os.environ['SPCONV_ALGO'] = 'native'        # Can be 'native' or 'auto', default is 'auto'.
                                            # 'auto' is faster but will do benchmarking at the beginning.
                                            # Recommended to set to 'native' if run only once.
import imageio
from PIL import Image
from trellis.pipelines import TrellisImageTo3DPipeline
from trellis.utils import render_utils, postprocessing_utils

# Load a pipeline from a model folder or a Hugging Face model hub.
pipeline = TrellisImageTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-image-large")
pipeline.cuda()

os.chdir("/content") # or main entry in kaggle

# Load an image
image = Image.open('path/to/the/image')

# Run the pipeline
outputs = pipeline.run(
    image,
    seed=1,
    # Optional parameters
    # sparse_structure_sampler_params={
    #     "steps": 12,
    #     "cfg_strength": 7.5,
    # },
    # slat_sampler_params={
    #     "steps": 12,
    #     "cfg_strength": 3,
    # },
)
# outputs is a dictionary containing generated 3D assets in different formats:
# - outputs['gaussian']: a list of 3D Gaussians
# - outputs['radiance_field']: a list of radiance fields
# - outputs['mesh']: a list of meshes

# Render the outputs
video = render_utils.render_video(outputs['gaussian'][0])['color']
imageio.mimsave("sample_gs.mp4", video, fps=30)
video = render_utils.render_video(outputs['radiance_field'][0])['color']
imageio.mimsave("sample_rf.mp4", video, fps=30)
video = render_utils.render_video(outputs['mesh'][0])['normal']
imageio.mimsave("sample_mesh.mp4", video, fps=30)

# GLB files can be extracted from the outputs
glb = postprocessing_utils.to_glb(
    outputs['gaussian'][0],
    outputs['mesh'][0],
    # Optional parameters
    simplify=0.95,          # Ratio of triangles to remove in the simplification process
    texture_size=1024,      # Size of the texture used for the GLB
)
glb.export("sample.glb")

# Save Gaussians as PLY files
outputs['gaussian'][0].save_ply("sample.ply")

🌟 Features

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation".

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.1%
  • Cuda 1.6%
  • Other 2.3%