Accelerate your 3D printing journey: https://www.kickstarter.com/projects/3dprinteracademy/intro-to-fdm-3d-printing-zero-to-hero
Newly released code allows you to create actual 3D models directly from text and you can 3D print them!
SHAP-E CODE:
__________
# Code snippet #1
!git clone https://github.com/openai/shap-e.git
__________
# Code snippet #2
%cd shap-e
__________
# Code snippet #3
!pip install -e .
__________
# Code snippet #4
import torch
from shap_e.diffusion.sample import sample_latents
from shap_e.diffusion.gaussian_diffusion import diffusion_from_config
from shap_e.models.download import load_model, load_config
from shap_e.util.notebooks import create_pan_cameras, decode_latent_images, gif_widget
__________
# Code snippet #5
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
__________
# Code snippet #6
xm = load_model('transmitter', device=device)
model = load_model('text300M', device=device)
diffusion = diffusion_from_config(load_config('diffusion'))
__________
# Code snippet #7
batch_size = 4
guidance_scale = 15.0
prompt = "shark"
latents = sample_latents(
batch_size=batch_size,
model=model,
diffusion=diffusion,
guidance_scale=guidance_scale,
model_kwargs=dict(texts=[prompt] * batch_size),
progress=True,
clip_denoised=True,
use_fp16=True,
use_karras=True,
karras_steps=64,
sigma_min=1e-3,
sigma_max=160,
s_churn=0,
)
__________
# Code snippet #8
render_mode = 'nerf' # you can change this to 'stf'
size = 128 # this is the size of the renders; higher values take longer to render.
cameras = create_pan_cameras(size, device)
for i, latent in enumerate(latents):
images = decode_latent_images(xm, latent, cameras, rendering_mode=render_mode)
display(gif_widget(images))
__________
# Code snippet #9
# Example of saving the latents as meshes.
from shap_e.util.notebooks import decode_latent_mesh
for i, latent in enumerate(latents):
t = decode_latent_mesh(xm, latent).tri_mesh()
with open(f'shark_mesh_{i}.ply', 'wb') as f:
t.write_ply(f)
with open(f'shark_mesh_{i}.obj', 'w') as f:
t.write_obj(f)