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

Function prepare_image

diffusers/examples/community/rerender_a_video.py:230–251  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

228
229
230def prepare_image(image):
231 if isinstance(image, torch.Tensor):
232 # Batch single image
233 if image.ndim == 3:
234 image = image.unsqueeze(0)
235
236 image = image.to(dtype=torch.float32)
237 else:
238 # preprocess image
239 if isinstance(image, (PIL.Image.Image, np.ndarray)):
240 image = [image]
241
242 if isinstance(image, list) and isinstance(image[0], PIL.Image.Image):
243 image = [np.array(i.convert("RGB"))[None, :] for i in image]
244 image = np.concatenate(image, axis=0)
245 elif isinstance(image, list) and isinstance(image[0], np.ndarray):
246 image = np.concatenate([i[None, :] for i in image], axis=0)
247
248 image = image.transpose(0, 3, 1, 2)
249 image = torch.from_numpy(image).to(dtype=torch.float32) / 127.5 - 1.0
250
251 return image
252
253
254class RerenderAVideoPipeline(StableDiffusionControlNetImg2ImgPipeline):

Callers

nothing calls this directly

Calls 2

transposeMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected