first commit

This commit is contained in:
Alex Nichol
2023-04-19 11:54:08 -07:00
commit 0f875ac43e
224 changed files with 788788 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"\n",
"from shap_e.models.download import load_model\n",
"from shap_e.util.data_util import load_or_create_multimodal_batch\n",
"from shap_e.util.notebooks import create_pan_cameras, decode_latent_images, gif_widget"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xm = load_model('transmitter', device=device)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"model_path = \"example_data/cactus/object.obj\"\n",
"\n",
"# This may take a few minutes, since it requires rendering the model twice\n",
"# in two different modes.\n",
"batch = load_or_create_multimodal_batch(\n",
" device,\n",
" model_path=model_path,\n",
" mv_light_mode=\"basic\",\n",
" mv_image_size=256,\n",
" cache_dir=\"example_data/cactus/cached\",\n",
" verbose=True, # this will show Blender output during renders\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with torch.no_grad():\n",
" latent = xm.encoder.encode_to_bottleneck(batch)\n",
"\n",
" render_mode = 'stf' # you can change this to 'nerf'\n",
" size = 128 # recommended that you lower resolution when using nerf\n",
"\n",
" cameras = create_pan_cameras(size, device)\n",
" images = decode_latent_images(xm, latent, cameras, rendering_mode=render_mode)\n",
" display(gif_widget(images))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,52 @@
newmtl mat0
Ka 0.0000 0.7000 0.0000
Kd 0.0000 0.7000 0.0000
Ks 0.0000 0.0000 0.0000
newmtl mat1
Ka 0.6600 0.4400 0.2000
Kd 0.6600 0.4400 0.2000
Ks 0.0000 0.0000 0.0000
newmtl mat2
Ka 0.3000 0.3000 0.3000
Kd 0.3000 0.3000 0.3000
Ks 0.0000 0.0000 0.0000
newmtl mat3
Ka 0.0000 0.5000 0.0000
Kd 0.0000 0.5000 0.0000
Ks 0.0000 0.0000 0.0000
newmtl mat4
Ka 0.0000 0.5667 0.0000
Kd 0.0000 0.5667 0.0000
Ks 0.0000 0.0000 0.0000
newmtl mat5
Ka 0.5400 0.3933 0.2333
Kd 0.5400 0.3933 0.2333
Ks 0.0000 0.0000 0.0000
newmtl mat6
Ka 0.0000 0.6333 0.0000
Kd 0.0000 0.6333 0.0000
Ks 0.0000 0.0000 0.0000
newmtl mat7
Ka 0.2000 0.3667 0.2000
Kd 0.2000 0.3667 0.2000
Ks 0.0000 0.0000 0.0000
newmtl mat8
Ka 0.4200 0.3467 0.2667
Kd 0.4200 0.3467 0.2667
Ks 0.0000 0.0000 0.0000
newmtl mat9
Ka 0.1000 0.4333 0.1000
Kd 0.1000 0.4333 0.1000
Ks 0.0000 0.0000 0.0000
newmtl mat10
Ka 0.1000 0.5667 0.1000
Kd 0.1000 0.5667 0.1000
Ks 0.0000 0.0000 0.0000
newmtl mat11
Ka 0.2000 0.4333 0.2000
Kd 0.2000 0.4333 0.2000
Ks 0.0000 0.0000 0.0000
newmtl mat12
Ka 0.1000 0.5000 0.1000
Kd 0.1000 0.5000 0.1000
Ks 0.0000 0.0000 0.0000

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "964ccced",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"\n",
"from shap_e.diffusion.sample import sample_latents\n",
"from shap_e.diffusion.gaussian_diffusion import diffusion_from_config\n",
"from shap_e.models.download import load_model, load_config\n",
"from shap_e.util.notebooks import create_pan_cameras, decode_latent_images, gif_widget\n",
"from shap_e.util.image_util import load_image"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8eed3a76",
"metadata": {},
"outputs": [],
"source": [
"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d922637",
"metadata": {},
"outputs": [],
"source": [
"xm = load_model('transmitter', device=device)\n",
"model = load_model('image300M', device=device)\n",
"diffusion = diffusion_from_config(load_config('diffusion'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53d329d0",
"metadata": {},
"outputs": [],
"source": [
"batch_size = 4\n",
"guidance_scale = 3.0\n",
"\n",
"image = load_image(\"example_data/corgi.png\")\n",
"\n",
"latents = sample_latents(\n",
" batch_size=batch_size,\n",
" model=model,\n",
" diffusion=diffusion,\n",
" guidance_scale=guidance_scale,\n",
" model_kwargs=dict(images=[image] * batch_size),\n",
" progress=True,\n",
" clip_denoised=True,\n",
" use_fp16=True,\n",
" use_karras=True,\n",
" karras_steps=64,\n",
" sigma_min=1e-3,\n",
" sigma_max=160,\n",
" s_churn=0,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "633da2ec",
"metadata": {},
"outputs": [],
"source": [
"render_mode = 'nerf' # you can change this to 'stf' for mesh rendering\n",
"size = 64 # this is the size of the renders; higher values take longer to render.\n",
"\n",
"cameras = create_pan_cameras(size, device)\n",
"for i, latent in enumerate(latents):\n",
" images = decode_latent_images(xm, latent, cameras, rendering_mode=render_mode)\n",
" display(gif_widget(images))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "964ccced",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"\n",
"from shap_e.diffusion.sample import sample_latents\n",
"from shap_e.diffusion.gaussian_diffusion import diffusion_from_config\n",
"from shap_e.models.download import load_model, load_config\n",
"from shap_e.util.notebooks import create_pan_cameras, decode_latent_images, gif_widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8eed3a76",
"metadata": {},
"outputs": [],
"source": [
"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d922637",
"metadata": {},
"outputs": [],
"source": [
"xm = load_model('transmitter', device=device)\n",
"model = load_model('text300M', device=device)\n",
"diffusion = diffusion_from_config(load_config('diffusion'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53d329d0",
"metadata": {},
"outputs": [],
"source": [
"batch_size = 4\n",
"guidance_scale = 15.0\n",
"prompt = \"a shark\"\n",
"\n",
"latents = sample_latents(\n",
" batch_size=batch_size,\n",
" model=model,\n",
" diffusion=diffusion,\n",
" guidance_scale=guidance_scale,\n",
" model_kwargs=dict(texts=[prompt] * batch_size),\n",
" progress=True,\n",
" clip_denoised=True,\n",
" use_fp16=True,\n",
" use_karras=True,\n",
" karras_steps=64,\n",
" sigma_min=1e-3,\n",
" sigma_max=160,\n",
" s_churn=0,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "633da2ec",
"metadata": {},
"outputs": [],
"source": [
"render_mode = 'nerf' # you can change this to 'stf'\n",
"size = 64 # this is the size of the renders; higher values take longer to render.\n",
"\n",
"cameras = create_pan_cameras(size, device)\n",
"for i, latent in enumerate(latents):\n",
" images = decode_latent_images(xm, latent, cameras, rendering_mode=render_mode)\n",
" display(gif_widget(images))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}