Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
TRELLIS/example.py at main · arsenal-open-source/TRELLIS · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
arsenal-open-source
TRELLIS
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
TRELLIS
/
example.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
57 lines (50 loc) · 2.05 KB
main
Breadcrumbs
TRELLIS
/
example.py
Copy path
Top
File metadata and controls
Code
Blame
57 lines (50 loc) · 2.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import
os
# os.environ['ATTN_BACKEND'] = 'xformers' # Can be 'flash-attn' or 'xformers', default is 'flash-attn'
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
(
"microsoft/TRELLIS-image-large"
)
pipeline
.
cuda
()
# Load an image
image
=
Image
.
open
(
"assets/example_image/T.png"
)
# 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"
)
You can’t perform that action at this time.