root commited on
Commit
b5919b4
·
1 Parent(s): 92ad990

swapping models

Browse files
download_weights.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path, PurePosixPath
3
+
4
+ from huggingface_hub import hf_hub_download
5
+
6
+
7
+ def prepare_base_model():
8
+ print(f'Preparing base stable-diffusion-v1-5 weights...')
9
+ local_dir = "./pretrained_weights/stable-diffusion-v1-5"
10
+ os.makedirs(local_dir, exist_ok=True)
11
+ for hub_file in ["unet/config.json", "unet/diffusion_pytorch_model.bin"]:
12
+ path = Path(hub_file)
13
+ saved_path = local_dir / path
14
+ if os.path.exists(saved_path):
15
+ continue
16
+ hf_hub_download(
17
+ repo_id="runwayml/stable-diffusion-v1-5",
18
+ subfolder=PurePosixPath(path.parent),
19
+ filename=PurePosixPath(path.name),
20
+ local_dir=local_dir,
21
+ )
22
+
23
+
24
+ def prepare_image_encoder():
25
+ print(f"Preparing image encoder weights...")
26
+ local_dir = "./pretrained_weights"
27
+ os.makedirs(local_dir, exist_ok=True)
28
+ for hub_file in ["image_encoder/config.json", "image_encoder/pytorch_model.bin"]:
29
+ path = Path(hub_file)
30
+ saved_path = local_dir / path
31
+ if os.path.exists(saved_path):
32
+ continue
33
+ hf_hub_download(
34
+ repo_id="lambdalabs/sd-image-variations-diffusers",
35
+ subfolder=PurePosixPath(path.parent),
36
+ filename=PurePosixPath(path.name),
37
+ local_dir=local_dir,
38
+ )
39
+
40
+
41
+ def prepare_dwpose():
42
+ print(f"Preparing DWPose weights...")
43
+ local_dir = "./pretrained_weights/DWPose"
44
+ os.makedirs(local_dir, exist_ok=True)
45
+ for hub_file in [
46
+ "dw-ll_ucoco_384.onnx",
47
+ "yolox_l.onnx",
48
+ ]:
49
+ path = Path(hub_file)
50
+ saved_path = local_dir / path
51
+ if os.path.exists(saved_path):
52
+ continue
53
+
54
+ hf_hub_download(
55
+ repo_id="yzd-v/DWPose",
56
+ subfolder=PurePosixPath(path.parent),
57
+ filename=PurePosixPath(path.name),
58
+ local_dir=local_dir,
59
+ )
60
+
61
+
62
+ def prepare_vae():
63
+ print(f"Preparing vae weights...")
64
+ local_dir = "./pretrained_weights/sd-vae-ft-mse"
65
+ os.makedirs(local_dir, exist_ok=True)
66
+ for hub_file in [
67
+ "config.json",
68
+ "diffusion_pytorch_model.bin",
69
+ ]:
70
+ path = Path(hub_file)
71
+ saved_path = local_dir / path
72
+ if os.path.exists(saved_path):
73
+ continue
74
+
75
+ hf_hub_download(
76
+ repo_id="stabilityai/sd-vae-ft-mse",
77
+ subfolder=PurePosixPath(path.parent),
78
+ filename=PurePosixPath(path.name),
79
+ local_dir=local_dir,
80
+ )
81
+
82
+
83
+ def prepare_anyone():
84
+ print(f"Preparing AnimateAnyone weights...")
85
+ local_dir = "./pretrained_weights"
86
+ os.makedirs(local_dir, exist_ok=True)
87
+ for hub_file in [
88
+ "denoising_unet.pth",
89
+ "motion_module.pth",
90
+ "pose_guider.pth",
91
+ "reference_unet.pth",
92
+ ]:
93
+ path = Path(hub_file)
94
+ saved_path = local_dir / path
95
+ if os.path.exists(saved_path):
96
+ continue
97
+
98
+ hf_hub_download(
99
+ repo_id="patrolli/AnimateAnyone",
100
+ subfolder=PurePosixPath(path.parent),
101
+ filename=PurePosixPath(path.name),
102
+ local_dir=local_dir,
103
+ )
104
+
105
+ if __name__ == '__main__':
106
+ prepare_base_model()
107
+ prepare_image_encoder()
108
+ prepare_dwpose()
109
+ prepare_vae()
110
+ prepare_anyone()
111
+
handler.py CHANGED
@@ -50,8 +50,7 @@ class EndpointHandler():
50
  pretrained_base_model_path_unet = os.path.join(base_dir, 'pretrained_weights', 'stable-diffusion-v1-5', 'unet')
51
  print("model path is " + pretrained_base_model_path_unet)
52
  reference_unet = UNet2DConditionModel.from_pretrained(
53
- pretrained_base_model_path_unet,
54
- use_safetensors = True
55
  ).to(dtype=self.weight_dtype, device="cuda")
56
 
57
  inference_config_path = os.path.join(base_dir, 'configs', 'inference', 'inference_v2.yaml')
 
50
  pretrained_base_model_path_unet = os.path.join(base_dir, 'pretrained_weights', 'stable-diffusion-v1-5', 'unet')
51
  print("model path is " + pretrained_base_model_path_unet)
52
  reference_unet = UNet2DConditionModel.from_pretrained(
53
+ pretrained_base_model_path_unet
 
54
  ).to(dtype=self.weight_dtype, device="cuda")
55
 
56
  inference_config_path = os.path.join(base_dir, 'configs', 'inference', 'inference_v2.yaml')
pretrained_weights/sd-vae-ft-mse/diffusion_pytorch_model.safetensors DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:a1d993488569e928462932c8c38a0760b874d166399b14414135bd9c42df5815
3
- size 334643276
 
 
 
 
pretrained_weights/stable-diffusion-v1-5/feature_extractor/preprocessor_config.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "crop_size": 224,
3
- "do_center_crop": true,
4
- "do_convert_rgb": true,
5
- "do_normalize": true,
6
- "do_resize": true,
7
- "feature_extractor_type": "CLIPFeatureExtractor",
8
- "image_mean": [
9
- 0.48145466,
10
- 0.4578275,
11
- 0.40821073
12
- ],
13
- "image_std": [
14
- 0.26862954,
15
- 0.26130258,
16
- 0.27577711
17
- ],
18
- "resample": 3,
19
- "size": 224
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pretrained_weights/stable-diffusion-v1-5/model_index.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "_class_name": "StableDiffusionPipeline",
3
- "_diffusers_version": "0.6.0",
4
- "feature_extractor": [
5
- "transformers",
6
- "CLIPImageProcessor"
7
- ],
8
- "safety_checker": [
9
- "stable_diffusion",
10
- "StableDiffusionSafetyChecker"
11
- ],
12
- "scheduler": [
13
- "diffusers",
14
- "PNDMScheduler"
15
- ],
16
- "text_encoder": [
17
- "transformers",
18
- "CLIPTextModel"
19
- ],
20
- "tokenizer": [
21
- "transformers",
22
- "CLIPTokenizer"
23
- ],
24
- "unet": [
25
- "diffusers",
26
- "UNet2DConditionModel"
27
- ],
28
- "vae": [
29
- "diffusers",
30
- "AutoencoderKL"
31
- ]
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pretrained_weights/stable-diffusion-v1-5/v1-inference.yaml DELETED
@@ -1,70 +0,0 @@
1
- model:
2
- base_learning_rate: 1.0e-04
3
- target: ldm.models.diffusion.ddpm.LatentDiffusion
4
- params:
5
- linear_start: 0.00085
6
- linear_end: 0.0120
7
- num_timesteps_cond: 1
8
- log_every_t: 200
9
- timesteps: 1000
10
- first_stage_key: "jpg"
11
- cond_stage_key: "txt"
12
- image_size: 64
13
- channels: 4
14
- cond_stage_trainable: false # Note: different from the one we trained before
15
- conditioning_key: crossattn
16
- monitor: val/loss_simple_ema
17
- scale_factor: 0.18215
18
- use_ema: False
19
-
20
- scheduler_config: # 10000 warmup steps
21
- target: ldm.lr_scheduler.LambdaLinearScheduler
22
- params:
23
- warm_up_steps: [ 10000 ]
24
- cycle_lengths: [ 10000000000000 ] # incredibly large number to prevent corner cases
25
- f_start: [ 1.e-6 ]
26
- f_max: [ 1. ]
27
- f_min: [ 1. ]
28
-
29
- unet_config:
30
- target: ldm.modules.diffusionmodules.openaimodel.UNetModel
31
- params:
32
- image_size: 32 # unused
33
- in_channels: 4
34
- out_channels: 4
35
- model_channels: 320
36
- attention_resolutions: [ 4, 2, 1 ]
37
- num_res_blocks: 2
38
- channel_mult: [ 1, 2, 4, 4 ]
39
- num_heads: 8
40
- use_spatial_transformer: True
41
- transformer_depth: 1
42
- context_dim: 768
43
- use_checkpoint: True
44
- legacy: False
45
-
46
- first_stage_config:
47
- target: ldm.models.autoencoder.AutoencoderKL
48
- params:
49
- embed_dim: 4
50
- monitor: val/rec_loss
51
- ddconfig:
52
- double_z: true
53
- z_channels: 4
54
- resolution: 256
55
- in_channels: 3
56
- out_ch: 3
57
- ch: 128
58
- ch_mult:
59
- - 1
60
- - 2
61
- - 4
62
- - 4
63
- num_res_blocks: 2
64
- attn_resolutions: []
65
- dropout: 0.0
66
- lossconfig:
67
- target: torch.nn.Identity
68
-
69
- cond_stage_config:
70
- target: ldm.modules.encoders.modules.FrozenCLIPEmbedder
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -24,19 +24,18 @@ gradio==3.41.2
24
  onnxruntime-coreml==1.13.1; python_version == '3.9' and sys_platform == 'darwin' and platform_machine != 'arm64'
25
  transformers==4.41.1
26
 
27
- # Stuff huggingface is complaining about
28
- einops==0.4.1
29
- av==11.0.0
30
-
31
  # Add additional dependencies
32
  diffusers==0.24.0
33
  omegaconf==2.2.3
34
- safetensors==0.4.1
35
 
36
  # Face swap related dependencies
37
  facenet-pytorch==2.5.2
38
  dlib==19.22.0
39
 
 
 
 
 
40
  # Additional dependencies from the first list not present in the second list
41
  accelerate==0.21.0
42
  clip @ https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip#sha256=b5842c25da441d6c581b53a5c60e0c2127ebafe0f746f8e15561a006c6c3be6a
 
24
  onnxruntime-coreml==1.13.1; python_version == '3.9' and sys_platform == 'darwin' and platform_machine != 'arm64'
25
  transformers==4.41.1
26
 
 
 
 
 
27
  # Add additional dependencies
28
  diffusers==0.24.0
29
  omegaconf==2.2.3
 
30
 
31
  # Face swap related dependencies
32
  facenet-pytorch==2.5.2
33
  dlib==19.22.0
34
 
35
+ # Stuff huggingface is complaining about
36
+ einops==0.4.1
37
+ av==11.0.0
38
+
39
  # Additional dependencies from the first list not present in the second list
40
  accelerate==0.21.0
41
  clip @ https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip#sha256=b5842c25da441d6c581b53a5c60e0c2127ebafe0f746f8e15561a006c6c3be6a