(display=True, key=None, device="cuda")
| 92 | |
| 93 | |
| 94 | def load_img(display=True, key=None, device="cuda"): |
| 95 | image = get_interactive_image(key=key) |
| 96 | if image is None: |
| 97 | return None |
| 98 | if display: |
| 99 | st.image(image) |
| 100 | w, h = image.size |
| 101 | print(f"loaded input image of size ({w}, {h})") |
| 102 | width, height = map( |
| 103 | lambda x: x - x % 64, (w, h) |
| 104 | ) # resize to integer multiple of 64 |
| 105 | image = image.resize((width, height)) |
| 106 | image = np.array(image.convert("RGB")) |
| 107 | image = image[None].transpose(0, 3, 1, 2) |
| 108 | image = torch.from_numpy(image).to(dtype=torch.float32) / 127.5 - 1.0 |
| 109 | return image.to(device) |
| 110 | |
| 111 | |
| 112 | def run_txt2img( |
no test coverage detected