6
6
"id" : " c442uQJ_gUgy"
7
7
},
8
8
"source" : [
9
- " # **Deforum Stable Diffusion v0.4 (DEV) **\n " ,
10
- " [Stable Diffusion](https://github.com/CompVis/stable-diffusion) by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer and the [Stability.ai](https://stability.ai/) Team. [K Diffusion](https://github.com/crowsonkb/k-diffusion) by [Katherine Crowson](https://twitter.com/RiversHaveWings). You need to get the ckpt file and put it on your Google Drive first to use this. It can be downloaded from [HuggingFace](https://huggingface.co/CompVis/stable-diffusion).\n " ,
9
+ " # **Deforum Stable Diffusion v0.4**\n " ,
10
+ " [Stable Diffusion](https://github.com/CompVis/stable-diffusion) by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Bj \u00f6 rn Ommer and the [Stability.ai](https://stability.ai/) Team. [K Diffusion](https://github.com/crowsonkb/k-diffusion) by [Katherine Crowson](https://twitter.com/RiversHaveWings). You need to get the ckpt file and put it on your Google Drive first to use this. It can be downloaded from [HuggingFace](https://huggingface.co/CompVis/stable-diffusion).\n " ,
11
11
" \n " ,
12
12
" Notebook by [deforum](https://discord.gg/upmXXsrwZc)"
13
13
]
39
39
{
40
40
"cell_type" : " code" ,
41
41
"metadata" : {
42
- "id " : " TxIOPT0G5Lx1 " ,
43
- "cellView " : " form "
42
+ "cellView " : " form " ,
43
+ "id " : " TxIOPT0G5Lx1 "
44
44
},
45
45
"source" : [
46
46
" #@markdown **Model and Output Paths**\n " ,
96
96
" all_process = [\n " ,
97
97
" ['pip', 'install', 'torch==1.12.1+cu113', 'torchvision==0.13.1+cu113', '--extra-index-url', 'https://download.pytorch.org/whl/cu113'],\n " ,
98
98
" ['pip', 'install', 'omegaconf==2.2.3', 'einops==0.4.1', 'pytorch-lightning==1.7.4', 'torchmetrics==0.9.3', 'torchtext==0.13.1', 'transformers==4.21.2', 'kornia==0.6.7'],\n " ,
99
- " ['git', 'clone', 'https://github.com/deforum/stable-diffusion/tree/dev '],\n " ,
99
+ " ['git', 'clone', 'https://github.com/deforum/stable-diffusion'],\n " ,
100
100
" ['pip', 'install', '-e', 'git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers'],\n " ,
101
101
" ['pip', 'install', '-e', 'git+https://github.com/openai/CLIP.git@main#egg=clip'],\n " ,
102
102
" ['pip', 'install', 'accelerate', 'ftfy', 'jsonmerge', 'matplotlib', 'resize-right', 'timm', 'torchdiffeq'],\n " ,
169
169
" from ldm.models.diffusion.ddim import DDIMSampler\n " ,
170
170
" from ldm.models.diffusion.plms import PLMSSampler\n " ,
171
171
" \n " ,
172
- " def patch_conv(cls):\n " ,
173
- " init = cls.__init__\n " ,
174
- " def __init__(self, *args, **kwargs):\n " ,
175
- " return init(self, *args, **kwargs, padding_mode='circular')\n " ,
176
- " cls.__init__ = __init__\n " ,
177
- " \n " ,
178
- " \n " ,
179
172
" def sanitize(prompt):\n " ,
180
173
" whitelist = set('abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ')\n " ,
181
174
" tmp = ''.join(filter(whitelist.__contains__, prompt))\n " ,
452
445
" s = np.max(np.append(s,1.0))\n " ,
453
446
" torch.clamp_(img, -1*s, s)\n " ,
454
447
" torch.FloatTensor.div_(img, s)\n " ,
455
- " #if seamless:\n " ,
456
- " #print(\" >> changed to seamless tiling mode\" )\n " ,
457
- " # patch_conv(torch.nn.Conv2d)\n " ,
448
+ " \n " ,
458
449
" # Callback for samplers in the k-diffusion repo, called thus:\n " ,
459
450
" # callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i], 'denoised': denoised})\n " ,
460
451
" def k_callback_(args_dict):\n " ,
467
458
" is_masked = torch.logical_and(mask >= mask_schedule[args_dict['i']], mask != 0 )\n " ,
468
459
" new_img = init_noise * torch.where(is_masked,1,0) + args_dict['x'] * torch.where(is_masked,0,1)\n " ,
469
460
" args_dict['x'].copy_(new_img)\n " ,
470
- " #if seamless:\n " ,
471
- " #print(\" >> changed to seamless tiling mode\" )\n " ,
472
- " #patch_conv(torch.nn.Conv2d)\n " ,
473
461
" \n " ,
474
462
" # Function that is called on the image (img) and step (i) at each step\n " ,
475
463
" def img_callback_(img, i):\n " ,
561
549
" os.makedirs(args.outdir, exist_ok=True)\n " ,
562
550
" \n " ,
563
551
" sampler = PLMSSampler(model) if args.sampler == 'plms' else DDIMSampler(model)\n " ,
564
- " if seamless:\n " ,
565
- " print(\" >> changed to seamless tiling mode\" )\n " ,
566
552
" model_wrap = CompVisDenoiser(model)\n " ,
567
553
" batch_size = args.n_samples\n " ,
568
554
" prompt = args.prompt\n " ,
705
691
{
706
692
"cell_type" : " code" ,
707
693
"metadata" : {
708
- "id " : " CIUJ7lWI4v53 " ,
709
- "cellView " : " form "
694
+ "cellView " : " form " ,
695
+ "id " : " CIUJ7lWI4v53 "
710
696
},
711
697
"source" : [
712
- " #@markdown **Select Model**\n " ,
713
- " model_config = \" custom\" #@param [\" custom\" ,\" v1-inference.yaml\" ]\n " ,
698
+ " #@markdown **Select and Load Model**\n " ,
699
+ " \n " ,
700
+ " model_config = \" v1-inference.yaml\" #@param [\" custom\" ,\" v1-inference.yaml\" ]\n " ,
714
701
" model_checkpoint = \" sd-v1-4.ckpt\" #@param [\" custom\" ,\" sd-v1-4-full-ema.ckpt\" ,\" sd-v1-4.ckpt\" ,\" sd-v1-3-full-ema.ckpt\" ,\" sd-v1-3.ckpt\" ,\" sd-v1-2-full-ema.ckpt\" ,\" sd-v1-2.ckpt\" ,\" sd-v1-1-full-ema.ckpt\" ,\" sd-v1-1.ckpt\" ]\n " ,
715
- " custom_config_path = \" /content/stable-diffusion/configs/stable-diffusion/v1-inference.yaml \" #@param {type:\" string\" }\n " ,
702
+ " custom_config_path = \"\" #@param {type:\" string\" }\n " ,
716
703
" custom_checkpoint_path = \"\" #@param {type:\" string\" }\n " ,
717
704
" \n " ,
718
705
" load_on_run_all = True #@param {type: 'boolean'}\n " ,
719
706
" half_precision = True # check\n " ,
720
707
" check_sha256 = True #@param {type:\" boolean\" }\n " ,
721
708
" \n " ,
722
- " #@markdown **Textual Inversion**\n " ,
723
- " use_textual_inversion = \n " ,
724
- " embedding_type = \" .bin\" #@param [\" .bin\" ,\" .pt\" ]\n " ,
725
- " embedding_path= \" /content/drive/MyDrive/AI/models/character-pingu.bin\" #@param {type:\" string\" }\n " ,
726
- " \n " ,
727
- " #@markdown **Enable Seamless Animations**\n " ,
728
- " seamless = False #@param {type:\" boolean\" }\n " ,
729
- " if seamless:\n " ,
730
- " #print(\" >> changed to seamless tiling mode\" )\n " ,
731
- " patch_conv(torch.nn.Conv2d)\n " ,
732
- " \n " ,
733
709
" model_map = {\n " ,
734
710
" \" sd-v1-4-full-ema.ckpt\" : {'sha256': '14749efc0ae8ef0329391ad4436feb781b402f4fece4883c7ad8d10556d8a36a'},\n " ,
735
711
" \" sd-v1-4.ckpt\" : {'sha256': 'fe4efff1e174c627256e44ec2991ba279b3816e364b49f9be2abc0b3ff3f8556'},\n " ,
741
717
" \" sd-v1-1.ckpt\" : {'sha256': '86cd1d3ccb044d7ba8db743d717c9bac603c4043508ad2571383f954390f3cea'}\n " ,
742
718
" }\n " ,
743
719
" \n " ,
744
- " \n " ,
745
- " import shutil\n " ,
746
- " \n " ,
747
- " originalpt = r'/content/stable-diffusion/ldm/modules/embedding_managerpt.py'\n " ,
748
- " originalbin = r'/content/stable-diffusion/ldm/modules/embedding_managerbin.py'\n " ,
749
- " \n " ,
750
- " if embedding_type == \" .pt\" :\n " ,
751
- " file_path = \" /content/stable-diffusion/ldm/modules/embedding_manager.py\"\n " ,
752
- " if os.path.isfile(file_path):\n " ,
753
- " os.remove(file_path)\n " ,
754
- " shutil.copyfile(originalpt, file_path)\n " ,
755
- " print('using .pt embedding')\n " ,
756
- " elif embedding_type == \" .bin\" :\n " ,
757
- " file_path = \" /content/stable-diffusion/ldm/modules/embedding_manager.py\"\n " ,
758
- " if os.path.isfile(file_path):\n " ,
759
- " os.remove(file_path)\n " ,
760
- " shutil.copyfile(originalbin, file_path)\n " ,
761
- " print('using .bin embedding')\n " ,
762
- " \n " ,
763
720
" # config path\n " ,
764
721
" ckpt_config_path = custom_config_path if model_config == \" custom\" else os.path.join(models_path, model_config)\n " ,
765
722
" if os.path.exists(ckpt_config_path):\n " ,
793
750
" if ckpt_valid:\n " ,
794
751
" print(f\" Using ckpt: {ckpt_path}\" )\n " ,
795
752
" \n " ,
796
- " #@markdown **Load Model**\n " ,
797
- " \n " ,
798
753
" def load_model_from_config(config, ckpt, verbose=False, device='cuda', half_precision=True):\n " ,
799
754
" map_location = \" cuda\" #@param [\" cpu\" , \" cuda\" ]\n " ,
800
755
" print(f\" Loading model from {ckpt}\" )\n " ,
803
758
" print(f\" Global Step: {pl_sd['global_step']}\" )\n " ,
804
759
" sd = pl_sd[\" state_dict\" ]\n " ,
805
760
" model = instantiate_from_config(config.model)\n " ,
806
- " if embedding_path is not None:\n " ,
807
- " model.embedding_manager.load(embedding_path)\n " ,
808
- " device = torch.device(\" cuda\" ) if torch.cuda.is_available() else torch.device(\" cpu\" )\n " ,
809
761
" m, u = model.load_state_dict(sd, strict=False)\n " ,
810
762
" if len(m) > 0 and verbose:\n " ,
811
763
" print(\" missing keys:\" )\n " ,
822
774
" return model\n " ,
823
775
" \n " ,
824
776
" if load_on_run_all and ckpt_valid:\n " ,
825
- " if seamless:\n " ,
826
- " print(\" >> changed to seamless tiling mode\" )\n " ,
827
- " patch_conv.__init__(torch.nn.Conv2d)\n " ,
828
777
" local_config = OmegaConf.load(f\" {ckpt_config_path}\" )\n " ,
829
778
" model = load_model_from_config(local_config, f\" {ckpt_path}\" , half_precision=half_precision)\n " ,
830
- " if embedding_path is not None:\n " ,
831
- " model.embedding_manager.load(embedding_path)\n " ,
832
779
" device = torch.device(\" cuda\" ) if torch.cuda.is_available() else torch.device(\" cpu\" )\n " ,
833
780
" model = model.to(device)"
834
781
],
856
803
{
857
804
"cell_type" : " code" ,
858
805
"metadata" : {
859
- "id " : " 8HJN2TE3vh-J " ,
860
- "cellView " : " form "
806
+ "cellView " : " form " ,
807
+ "id " : " 8HJN2TE3vh-J "
861
808
},
862
809
"source" : [
863
810
" \n " ,
864
811
" def DeforumAnimArgs():\n " ,
865
812
" \n " ,
866
813
" #@markdown ####**Animation:**\n " ,
867
- " animation_mode = '3D ' #@param ['None', '2D', '3D', 'Video Input', 'Interpolation'] {type:'string'}\n " ,
814
+ " animation_mode = 'None ' #@param ['None', '2D', '3D', 'Video Input', 'Interpolation'] {type:'string'}\n " ,
868
815
" max_frames = 1000 #@param {type:\" number\" }\n " ,
869
816
" border = 'wrap' #@param ['wrap', 'replicate'] {type:'string'}\n " ,
870
817
" \n " ,
988
935
"source" : [
989
936
" \n " ,
990
937
" prompts = [\n " ,
991
- " \" a beautiful forest by Asher Brown Durand, * trending on Artstation\" , #the first prompt I want\n " ,
992
- " \" a beautiful portrait of a woman by Artgerm, * trending on Artstation\" , #the second prompt I want\n " ,
938
+ " \" a beautiful forest by Asher Brown Durand, trending on Artstation\" , #the first prompt I want\n " ,
939
+ " \" a beautiful portrait of a woman by Artgerm, trending on Artstation\" , #the second prompt I want\n " ,
993
940
" #\" the third prompt I don't want it I commented it with an\" ,\n " ,
994
941
" ]\n " ,
995
942
" \n " ,
996
943
" animation_prompts = {\n " ,
997
- " 0: \" * \" ,\n " ,
998
- " 20: \" a beautiful banana * , trending on Artstation\" ,\n " ,
999
- " 30: \" a beautiful coconut * , trending on Artstation\" ,\n " ,
1000
- " 40: \" a beautiful durian * , trending on Artstation\" ,\n " ,
944
+ " 0: \" a beautiful apple, trending on Artstation \" ,\n " ,
945
+ " 20: \" a beautiful banana, trending on Artstation\" ,\n " ,
946
+ " 30: \" a beautiful coconut, trending on Artstation\" ,\n " ,
947
+ " 40: \" a beautiful durian, trending on Artstation\" ,\n " ,
1001
948
" }"
1002
949
],
1003
950
"outputs" : [],
1019
966
"cellView" : " form"
1020
967
},
1021
968
"source" : [
1022
- " #@markdown **Load Settings**\n " ,
1023
969
" override_settings_with_file = False #@param {type:\" boolean\" }\n " ,
1024
970
" custom_settings_file = \" /content/drive/MyDrive/Settings.txt\" #@param {type:\" string\" }\n " ,
1025
971
" \n " ,
1049
995
" filename_format = \" {timestring}_{index}_{prompt}.png\" #@param [\" {timestring}_{index}_{seed}.png\" ,\" {timestring}_{index}_{prompt}.png\" ]\n " ,
1050
996
" seed_behavior = \" iter\" #@param [\" iter\" ,\" fixed\" ,\" random\" ]\n " ,
1051
997
" make_grid = False #@param {type:\" boolean\" }\n " ,
1052
- " grid_rows = 1 #@param \n " ,
998
+ " grid_rows = 2 #@param \n " ,
1053
999
" outdir = get_output_folder(output_path, batch_name)\n " ,
1054
1000
" \n " ,
1055
1001
" #@markdown **Init Settings**\n " ,
1550
1496
{
1551
1497
"cell_type" : " code" ,
1552
1498
"metadata" : {
1553
- "id " : " no2jP8HTMBM0 " ,
1554
- "cellView " : " form "
1499
+ "cellView " : " form " ,
1500
+ "id " : " no2jP8HTMBM0 "
1555
1501
},
1556
1502
"source" : [
1557
1503
" skip_video_for_run_all = True #@param {type: 'boolean'}\n " ,
1626
1572
}
1627
1573
},
1628
1574
"nbformat" : 4 ,
1629
- "nbformat_minor" : 0
1575
+ "nbformat_minor" : 4
1630
1576
}
0 commit comments