Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
camenduru authored Nov 22, 2023
1 parent 3147371 commit 2d411ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 11 additions & 9 deletions stable_video_diffusion_fp16_colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"from torchvision.transforms import ToTensor\n",
"from torchvision.transforms import functional as TF\n",
"from sgm.util import instantiate_from_config\n",
"from sgm.inference.helpers import embed_watermark\n",
"from scripts.util.detection.nsfw_and_watermark_dectection import DeepFloydDataFiltering\n",
"\n",
"def load_model(config: str, device: str, num_frames: int, num_steps: int):\n",
" config = OmegaConf.load(config)\n",
Expand All @@ -55,14 +53,13 @@
" config.model.params.sampler_config.params.guider_config.params.num_frames = (num_frames)\n",
" with torch.device(device):\n",
" model = instantiate_from_config(config.model).to(device).eval().requires_grad_(False)\n",
" filter = DeepFloydDataFiltering(verbose=False, device=device)\n",
" return model, filter\n",
" return model\n",
"\n",
"num_frames = 25\n",
"num_steps = 30\n",
"model_config = \"generative-models/scripts/sampling/configs/svd_xt.yaml\"\n",
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"model, filter = load_model(model_config, device, num_frames, num_steps)\n",
"model = load_model(model_config, device, num_frames, num_steps)\n",
"model.conditioner.cpu()\n",
"model.first_stage_model.cpu()\n",
"model.model.to(dtype=torch.float16)\n",
Expand Down Expand Up @@ -258,8 +255,6 @@
" fps_id + 1,\n",
" (samples.shape[-1], samples.shape[-2]),\n",
" )\n",
" samples = embed_watermark(samples)\n",
" samples = filter(samples)\n",
" vid = (\n",
" (rearrange(samples, \"t c h w -> t h w c\") * 255)\n",
" .cpu()\n",
Expand All @@ -271,8 +266,15 @@
" writer.write(frame)\n",
" writer.release()\n",
" all_out_paths.append(video_path)\n",
" return all_out_paths\n",
"\n",
" return all_out_paths"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"import random\n",
"\n",
Expand Down
20 changes: 11 additions & 9 deletions stable_video_diffusion_fp32_colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"from torchvision.transforms import ToTensor\n",
"from torchvision.transforms import functional as TF\n",
"from sgm.util import instantiate_from_config\n",
"from sgm.inference.helpers import embed_watermark\n",
"from scripts.util.detection.nsfw_and_watermark_dectection import DeepFloydDataFiltering\n",
"\n",
"def load_model(config: str, device: str, num_frames: int, num_steps: int):\n",
" config = OmegaConf.load(config)\n",
Expand All @@ -55,14 +53,13 @@
" config.model.params.sampler_config.params.guider_config.params.num_frames = (num_frames)\n",
" with torch.device(device):\n",
" model = instantiate_from_config(config.model).to(device).eval().requires_grad_(False)\n",
" filter = DeepFloydDataFiltering(verbose=False, device=device)\n",
" return model, filter\n",
" return model\n",
"\n",
"num_frames = 25\n",
"num_steps = 30\n",
"model_config = \"generative-models/scripts/sampling/configs/svd_xt.yaml\"\n",
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"model, filter = load_model(model_config, device, num_frames, num_steps)\n",
"model = load_model(model_config, device, num_frames, num_steps)\n",
"\n",
"def get_unique_embedder_keys_from_conditioner(conditioner):\n",
" return list(set([x.input_key for x in conditioner.embedders]))\n",
Expand Down Expand Up @@ -236,8 +233,6 @@
" fps_id + 1,\n",
" (samples.shape[-1], samples.shape[-2]),\n",
" )\n",
" samples = embed_watermark(samples)\n",
" samples = filter(samples)\n",
" vid = (\n",
" (rearrange(samples, \"t c h w -> t h w c\") * 255)\n",
" .cpu()\n",
Expand All @@ -249,8 +244,15 @@
" writer.write(frame)\n",
" writer.release()\n",
" all_out_paths.append(video_path)\n",
" return all_out_paths\n",
"\n",
" return all_out_paths"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"import random\n",
"\n",
Expand Down

0 comments on commit 2d411ba

Please sign in to comment.