Spaces:
Running on Zero
Running on Zero
Update ootd/inference_ootd.py
Browse files32 unmodified lines3334353637383924 unmodified lines6465666768697071727374752 unmodified lines7879808182838422 unmodified lines10710810911011111211311411511611711811912032 unmodified linesclass OOTDiffusion:def __init__(self, gpu_id):self.gpu_id = 'cuda:' + str(gpu_id)vae = AutoencoderKL.from_pretrained(VAE_PATH,24 unmodified linesuse_safetensors=True,safety_checker=None,requires_safety_checker=False,).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.tokenizer = CLIPTokenizer.from_pretrained(MODEL_PATH,2 unmodified linesself.text_encoder = CLIPTextModel.from_pretrained(MODEL_PATH,subfolder="text_encoder",).to(self.gpu_id)def tokenize_captions(self, captions, max_length):22 unmodified linesgenerator = 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.image_encoder(prompt_image.data['pixel_values']).image_embedsprompt_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[:, 1:] = prompt_image[:]elif model_type == 'dc':prompt_embeds = self.text_encoder(self.tokenize_captions([category], 3).to(self.gpu_id))[0]prompt_embeds = torch.cat([prompt_embeds, prompt_image], dim=1)else:raise ValueError("model_type must be \'hd\' or \'dc\'!")32 unmodified lines3334353637383924 unmodified lines6465666768697071727374752 unmodified lines7879808182838422 unmodified lines10710810911011111211311411511611711811912032 unmodified linesclass OOTDiffusion:def __init__(self, gpu_id):# self.gpu_id = 'cuda:' + str(gpu_id)vae = AutoencoderKL.from_pretrained(VAE_PATH,24 unmodified linesuse_safetensors=True,safety_checker=None,requires_safety_checker=False,)#.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.tokenizer = CLIPTokenizer.from_pretrained(MODEL_PATH,2 unmodified linesself.text_encoder = CLIPTextModel.from_pretrained(MODEL_PATH,subfolder="text_encoder",)#.to(self.gpu_id)def tokenize_captions(self, captions, max_length):22 unmodified linesgenerator = torch.manual_seed(seed)with torch.no_grad():prompt_image = self.auto_processor(images=image_garm, return_tensors="pt").to('cuda')prompt_image = self.image_encoder(prompt_image.data['pixel_values']).image_embedsprompt_image = prompt_image.unsqueeze(1)if model_type == 'hd':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('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.py+7-7