MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / load_image

Function load_image

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 3

transposeMethod · 0.80
cropMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected