Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -74,19 +74,19 @@ args = parser.parse_args()
|
|
74 |
|
75 |
args.device = "cuda"
|
76 |
|
77 |
-
base_path = 'feishen29/IMAGDressing-v1'
|
78 |
|
79 |
|
80 |
-
vae = AutoencoderKL.from_pretrained('
|
81 |
-
tokenizer = CLIPTokenizer.from_pretrained("
|
82 |
-
text_encoder = CLIPTextModel.from_pretrained("
|
83 |
-
image_encoder = CLIPVisionModelWithProjection.from_pretrained(
|
84 |
-
unet = UNet2DConditionModel.from_pretrained("
|
85 |
|
86 |
# image_face_fusion = pipeline('face_fusion_torch', model='damo/cv_unet_face_fusion_torch', model_revision='v1.0.3')
|
87 |
|
88 |
#face_model
|
89 |
-
app = FaceAnalysis(model_path=
|
90 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
91 |
|
92 |
# def ref proj weight
|
@@ -126,7 +126,7 @@ adapter_modules = torch.nn.ModuleList(unet.attn_processors.values())
|
|
126 |
adapter_modules = adapter_modules.to(dtype=torch.float16, device=args.device)
|
127 |
del st
|
128 |
|
129 |
-
ref_unet = UNet2DConditionModel.from_pretrained("
|
130 |
dtype=torch.float16,
|
131 |
device=args.device)
|
132 |
ref_unet.set_attn_processor(
|
@@ -167,7 +167,7 @@ noise_scheduler = DDIMScheduler(
|
|
167 |
# noise_scheduler = UniPCMultistepScheduler.from_config(args.pretrained_model_name_or_path, subfolder="scheduler")
|
168 |
|
169 |
control_net_openpose = ControlNetModel.from_pretrained(
|
170 |
-
"
|
171 |
torch_dtype=torch.float16).to(device=args.device)
|
172 |
# pipe = PipIpaControlNet(unet=unet, reference_unet=ref_unet, vae=vae, tokenizer=tokenizer,
|
173 |
# text_encoder=text_encoder, image_encoder=image_encoder,
|
@@ -183,7 +183,7 @@ img_transform = transforms.Compose([
|
|
183 |
transforms.Normalize([0.5], [0.5]),
|
184 |
])
|
185 |
|
186 |
-
openpose_model = OpenposeDetector.from_pretrained(
|
187 |
|
188 |
def resize_img(input_image, max_side=640, min_side=512, size=None,
|
189 |
pad_to_max_side=False, mode=Image.BILINEAR, base_pixel_number=64):
|
|
|
74 |
|
75 |
args.device = "cuda"
|
76 |
|
77 |
+
# base_path = 'feishen29/IMAGDressing-v1'
|
78 |
|
79 |
|
80 |
+
vae = AutoencoderKL.from_pretrained('stabilityai/sd-vae-ft-mse').to(dtype=torch.float16, device=args.device)
|
81 |
+
tokenizer = CLIPTokenizer.from_pretrained("SG161222/Realistic_Vision_V4.0_noVAE", subfolder="tokenizer")
|
82 |
+
text_encoder = CLIPTextModel.from_pretrained("SG161222/Realistic_Vision_V4.0_noVAE", subfolder="text_encoder").to(dtype=torch.float16, device=args.device)
|
83 |
+
image_encoder = CLIPVisionModelWithProjection.from_pretrained("h94/IP-Adapter", subfolder="models/image_encoder").to(dtype=torch.float16, device=args.device)
|
84 |
+
unet = UNet2DConditionModel.from_pretrained("SG161222/Realistic_Vision_V4.0_noVAE", subfolder="unet").to(dtype=torch.float16,device=args.device)
|
85 |
|
86 |
# image_face_fusion = pipeline('face_fusion_torch', model='damo/cv_unet_face_fusion_torch', model_revision='v1.0.3')
|
87 |
|
88 |
#face_model
|
89 |
+
app = FaceAnalysis(model_path="buffalo_l", providers=[('CUDAExecutionProvider', {"device_id": args.device})]) ##使用GPU:0, 默认使用buffalo_l就可以了
|
90 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
91 |
|
92 |
# def ref proj weight
|
|
|
126 |
adapter_modules = adapter_modules.to(dtype=torch.float16, device=args.device)
|
127 |
del st
|
128 |
|
129 |
+
ref_unet = UNet2DConditionModel.from_pretrained("SG161222/Realistic_Vision_V4.0_noVAE", subfolder="unet").to(
|
130 |
dtype=torch.float16,
|
131 |
device=args.device)
|
132 |
ref_unet.set_attn_processor(
|
|
|
167 |
# noise_scheduler = UniPCMultistepScheduler.from_config(args.pretrained_model_name_or_path, subfolder="scheduler")
|
168 |
|
169 |
control_net_openpose = ControlNetModel.from_pretrained(
|
170 |
+
"lllyasviel/control_v11p_sd15_openpose",
|
171 |
torch_dtype=torch.float16).to(device=args.device)
|
172 |
# pipe = PipIpaControlNet(unet=unet, reference_unet=ref_unet, vae=vae, tokenizer=tokenizer,
|
173 |
# text_encoder=text_encoder, image_encoder=image_encoder,
|
|
|
183 |
transforms.Normalize([0.5], [0.5]),
|
184 |
])
|
185 |
|
186 |
+
openpose_model = OpenposeDetector.from_pretrained('lllyasviel/ControlNet').to(args.device)
|
187 |
|
188 |
def resize_img(input_image, max_side=640, min_side=512, size=None,
|
189 |
pad_to_max_side=False, mode=Image.BILINEAR, base_pixel_number=64):
|