(image, size)
| 377 | |
| 378 | |
| 379 | def process_image(image, size): |
| 380 | image = exif_transpose(image) |
| 381 | |
| 382 | if not image.mode == "RGB": |
| 383 | image = image.convert("RGB") |
| 384 | |
| 385 | orig_height = image.height |
| 386 | orig_width = image.width |
| 387 | |
| 388 | image = transforms.Resize(size, interpolation=transforms.InterpolationMode.BILINEAR)(image) |
| 389 | |
| 390 | c_top, c_left, _, _ = transforms.RandomCrop.get_params(image, output_size=(size, size)) |
| 391 | image = transforms.functional.crop(image, c_top, c_left, size, size) |
| 392 | |
| 393 | image = transforms.ToTensor()(image) |
| 394 | |
| 395 | micro_conds = torch.tensor( |
| 396 | [orig_width, orig_height, c_top, c_left, 6.0], |
| 397 | ) |
| 398 | |
| 399 | return {"image": image, "micro_conds": micro_conds} |
| 400 | |
| 401 | |
| 402 | def tokenize_prompt(tokenizer, prompt): |
no test coverage detected