MCPcopy Index your code
hub / github.com/huggingface/diffusers / load_image

Function load_image

scripts/convert_consistency_decoder.py:193–211  ·  view source on GitHub ↗
(uri, size=None, center_crop=False)

Source from the content-addressed store, hash-verified

191
192
193def 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
214class TimestepEmbedding_(nn.Module):

Callers 1

Calls 4

floatMethod · 0.80
transposeMethod · 0.80
cropMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…