(images, num_rows=1, offset_ratio=0.02)
| 35 | |
| 36 | |
| 37 | def view_images(images, num_rows=1, offset_ratio=0.02): |
| 38 | if type(images) is list: |
| 39 | num_empty = len(images) % num_rows |
| 40 | elif images.ndim == 4: |
| 41 | num_empty = images.shape[0] % num_rows |
| 42 | else: |
| 43 | images = [images] |
| 44 | num_empty = 0 |
| 45 | |
| 46 | empty_images = np.ones(images[0].shape, dtype=np.uint8) * 255 |
| 47 | images = [image.astype(np.uint8) for image in images] + [empty_images] * num_empty |
| 48 | num_items = len(images) |
| 49 | |
| 50 | h, w, c = images[0].shape |
| 51 | offset = int(h * offset_ratio) |
| 52 | num_cols = num_items // num_rows |
| 53 | image_ = np.ones((h * num_rows + offset * (num_rows - 1), |
| 54 | w * num_cols + offset * (num_cols - 1), 3), dtype=np.uint8) * 255 |
| 55 | for i in range(num_rows): |
| 56 | for j in range(num_cols): |
| 57 | image_[i * (h + offset): i * (h + offset) + h:, j * (w + offset): j * (w + offset) + w] = images[ |
| 58 | i * num_cols + j] |
| 59 | |
| 60 | pil_img = Image.fromarray(image_) |
| 61 | display(pil_img) |
| 62 | |
| 63 | |
| 64 | def diffusion_step(model, controller, latents, context, t, guidance_scale, low_resource=False): |
nothing calls this directly
no outgoing calls
no test coverage detected