(self, image, num_frames, height, width)
| 153 | |
| 154 | |
| 155 | def encode_image(self, image, num_frames, height, width): |
| 156 | image = self.preprocess_image(image.resize((width, height))).to(self.device) |
| 157 | clip_context = self.image_encoder.encode_image([image]) |
| 158 | msk = torch.ones(1, num_frames, height//8, width//8, device=self.device) |
| 159 | msk[:, 1:] = 0 |
| 160 | msk = torch.concat([torch.repeat_interleave(msk[:, 0:1], repeats=4, dim=1), msk[:, 1:]], dim=1) |
| 161 | msk = msk.view(1, msk.shape[1] // 4, 4, height//8, width//8) |
| 162 | msk = msk.transpose(1, 2)[0] |
| 163 | |
| 164 | vae_input = torch.concat([image.transpose(0, 1), torch.zeros(3, num_frames-1, height, width).to(image.device)], dim=1) |
| 165 | y = self.vae.encode([vae_input.to(dtype=self.torch_dtype, device=self.device)], device=self.device)[0] |
| 166 | y = torch.concat([msk, y]) |
| 167 | y = y.unsqueeze(0) |
| 168 | clip_context = clip_context.to(dtype=self.torch_dtype, device=self.device) |
| 169 | y = y.to(dtype=self.torch_dtype, device=self.device) |
| 170 | return {"clip_feature": clip_context, "y": y} |
| 171 | |
| 172 | |
| 173 |
no outgoing calls
no test coverage detected