MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / preprocess

Function preprocess

examples/community/imagic_stable_diffusion.py:50–57  ·  view source on GitHub ↗
(image)

Source from the content-addressed store, hash-verified

48
49
50def preprocess(image):
51 w, h = image.size
52 w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
53 image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"])
54 image = np.array(image).astype(np.float32) / 255.0
55 image = image[None].transpose(0, 3, 1, 2)
56 image = torch.from_numpy(image)
57 return 2.0 * image - 1.0
58
59
60class ImagicStableDiffusionPipeline(DiffusionPipeline, StableDiffusionMixin):

Callers 1

trainMethod · 0.70

Calls 2

transposeMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected