(uri, size=None, center_crop=False)
| 191 | |
| 192 | |
| 193 | def load_image(uri, size=None, center_crop=False): |
| 194 | import numpy as np |
| 195 | from PIL import Image |
| 196 | |
| 197 | image = Image.open(uri) |
| 198 | if center_crop: |
| 199 | image = image.crop( |
| 200 | ( |
| 201 | (image.width - min(image.width, image.height)) // 2, |
| 202 | (image.height - min(image.width, image.height)) // 2, |
| 203 | (image.width + min(image.width, image.height)) // 2, |
| 204 | (image.height + min(image.width, image.height)) // 2, |
| 205 | ) |
| 206 | ) |
| 207 | if size is not None: |
| 208 | image = image.resize(size) |
| 209 | image = torch.tensor(np.array(image).transpose(2, 0, 1)).unsqueeze(0).float() |
| 210 | image = image / 127.5 - 1.0 |
| 211 | return image |
| 212 | |
| 213 | |
| 214 | class TimestepEmbedding_(nn.Module): |
no test coverage detected
searching dependent graphs…