Spaces:
Sleeping
Sleeping
Update ootd/inference_ootd_hd.py
Browse files31 unmodified lines323334353536373824 unmodified lines63646566666768697071717273742 unmodified lines777879808081828322 unmodified lines10610710810910911011111211311311411511611611711811931 unmodified linesclass OOTDiffusionHD:
def __init__(self, gpu_id): self.gpu_id = 'cuda:' + str(gpu_id) # self.gpu_id = 'cuda:' + str(gpu_id)
vae = AutoencoderKL.from_pretrained( VAE_PATH,24 unmodified lines use_safetensors=True, safety_checker=None, requires_safety_checker=False, ).to(self.gpu_id) )#.to(self.gpu_id)
self.pipe.scheduler = UniPCMultistepScheduler.from_config(self.pipe.scheduler.config) self.auto_processor = AutoProcessor.from_pretrained(VIT_PATH) self.image_encoder = CLIPVisionModelWithProjection.from_pretrained(VIT_PATH).to(self.gpu_id) self.image_encoder = CLIPVisionModelWithProjection.from_pretrained(VIT_PATH)#.to(self.gpu_id)
self.tokenizer = CLIPTokenizer.from_pretrained( MODEL_PATH,2 unmodified lines self.text_encoder = CLIPTextModel.from_pretrained( MODEL_PATH, subfolder="text_encoder", ).to(self.gpu_id) )#.to(self.gpu_id)
def tokenize_captions(self, captions, max_length):22 unmodified lines generator = torch.manual_seed(seed)
with torch.no_grad(): prompt_image = self.auto_processor(images=image_garm, return_tensors="pt").to(self.gpu_id) prompt_image = self.auto_processor(images=image_garm, return_tensors="pt").to('cuda') prompt_image = self.image_encoder(prompt_image.data['pixel_values']).image_embeds prompt_image = prompt_image.unsqueeze(1) if model_type == 'hd': prompt_embeds = self.text_encoder(self.tokenize_captions([""], 2).to(self.gpu_id))[0] prompt_embeds = self.text_encoder(self.tokenize_captions([""], 2).to('cuda'))[0] prompt_embeds[:, 1:] = prompt_image[:] elif model_type == 'dc': prompt_embeds = self.text_encoder(self.tokenize_captions([category], 3).to(self.gpu_id))[0] prompt_embeds = self.text_encoder(self.tokenize_captions([category], 3).to('cuda'))[0] prompt_embeds = torch.cat([prompt_embeds, prompt_image], dim=1) else: raise ValueError("model_type must be \'hd\' or \'dc\'!")ootd/inference_ootd_hd.py+7-7