Created
May 5, 2023 15:57
-
-
Save udon-universe/bc54435d787b6d777d8298eac18b9866 to your computer and use it in GitHub Desktop.
try shap-e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install -e . | |
# + pip install blobfile pyyaml ipywidgets | |
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 | |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | |
xm = load_model('transmitter', device=device) | |
model = load_model('text300M', device=device) | |
diffusion = diffusion_from_config(load_config('diffusion')) | |
batch_size = 4 | |
guidance_scale = 15.0 | |
prompt = "udon" | |
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, | |
) | |
render_mode = 'nerf' # you can change this to 'stf' | |
size = 64 # 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) | |
for i, image in enumerate(images): | |
image.save(f"shap-e-sample{i}.jpg", quality=95) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment