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

Function prepare_image

diffusers/examples/community/fresco_v2v.py:1222–1243  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

1220
1221
1222def prepare_image(image):
1223 if isinstance(image, torch.Tensor):
1224 # Batch single image
1225 if image.ndim == 3:
1226 image = image.unsqueeze(0)
1227
1228 image = image.to(dtype=torch.float32)
1229 else:
1230 # preprocess image
1231 if isinstance(image, (PIL.Image.Image, np.ndarray)):
1232 image = [image]
1233
1234 if isinstance(image, list) and isinstance(image[0], PIL.Image.Image):
1235 image = [np.array(i.convert("RGB"))[None, :] for i in image]
1236 image = np.concatenate(image, axis=0)
1237 elif isinstance(image, list) and isinstance(image[0], np.ndarray):
1238 image = np.concatenate([i[None, :] for i in image], axis=0)
1239
1240 image = image.transpose(0, 3, 1, 2)
1241 image = torch.from_numpy(image).to(dtype=torch.float32) / 127.5 - 1.0
1242
1243 return image
1244
1245
1246class FrescoV2VPipeline(StableDiffusionControlNetImg2ImgPipeline):

Callers

nothing calls this directly

Calls 2

transposeMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected