Commit
·
cf3e24a
1
Parent(s):
6070ab2
Improve image transformation
Browse files- image_transformation.py +9 -9
image_transformation.py
CHANGED
|
@@ -30,7 +30,7 @@ IMAGE_TRANSFORMATION_DESCRIPTION = (
|
|
| 30 |
|
| 31 |
class ImageTransformationTool(Tool):
|
| 32 |
default_stable_diffusion_checkpoint = "runwayml/stable-diffusion-v1-5"
|
| 33 |
-
default_controlnet_checkpoint = "lllyasviel/
|
| 34 |
description = IMAGE_TRANSFORMATION_DESCRIPTION
|
| 35 |
inputs = ['image', 'text']
|
| 36 |
outputs = ['image']
|
|
@@ -67,11 +67,14 @@ class ImageTransformationTool(Tool):
|
|
| 67 |
self.stable_diffusion_checkpoint, controlnet=self.controlnet
|
| 68 |
)
|
| 69 |
self.pipeline.scheduler = UniPCMultistepScheduler.from_config(self.pipeline.scheduler.config)
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
self.is_initialized = True
|
| 73 |
|
| 74 |
-
def __call__(self, image,
|
| 75 |
if not self.is_initialized:
|
| 76 |
self.setup()
|
| 77 |
|
|
@@ -87,12 +90,9 @@ class ImageTransformationTool(Tool):
|
|
| 87 |
image = np.concatenate([image, image, image], axis=2)
|
| 88 |
canny_image = Image.fromarray(image)
|
| 89 |
|
| 90 |
-
generator = torch.Generator(device="cpu").manual_seed(2)
|
| 91 |
-
|
| 92 |
return self.pipeline(
|
| 93 |
-
prompt,
|
| 94 |
canny_image,
|
| 95 |
-
negative_prompt=
|
| 96 |
-
num_inference_steps=
|
| 97 |
-
generator=generator,
|
| 98 |
).images[0]
|
|
|
|
| 30 |
|
| 31 |
class ImageTransformationTool(Tool):
|
| 32 |
default_stable_diffusion_checkpoint = "runwayml/stable-diffusion-v1-5"
|
| 33 |
+
default_controlnet_checkpoint = "lllyasviel/control_v11p_sd15_canny"
|
| 34 |
description = IMAGE_TRANSFORMATION_DESCRIPTION
|
| 35 |
inputs = ['image', 'text']
|
| 36 |
outputs = ['image']
|
|
|
|
| 67 |
self.stable_diffusion_checkpoint, controlnet=self.controlnet
|
| 68 |
)
|
| 69 |
self.pipeline.scheduler = UniPCMultistepScheduler.from_config(self.pipeline.scheduler.config)
|
| 70 |
+
|
| 71 |
+
self.pipeline.to(device=device)
|
| 72 |
+
if self.device.type == "cuda":
|
| 73 |
+
self.pipeline.to(torch_dtype=torch.float16)
|
| 74 |
|
| 75 |
self.is_initialized = True
|
| 76 |
|
| 77 |
+
def __call__(self, image, negative_prompt="low quality, bad quality, deformed, low resolution", added_prompt=" , highest quality, highly realistic, very high resolution"):
|
| 78 |
if not self.is_initialized:
|
| 79 |
self.setup()
|
| 80 |
|
|
|
|
| 90 |
image = np.concatenate([image, image, image], axis=2)
|
| 91 |
canny_image = Image.fromarray(image)
|
| 92 |
|
|
|
|
|
|
|
| 93 |
return self.pipeline(
|
| 94 |
+
prompt + added_prompt,
|
| 95 |
canny_image,
|
| 96 |
+
negative_prompt=negative_prompt,
|
| 97 |
+
num_inference_steps=25,
|
|
|
|
| 98 |
).images[0]
|