Update README.md
Browse files
README.md
CHANGED
@@ -22,34 +22,46 @@ inference: true
|
|
22 |
should probably proofread and complete it, then remove this comment. -->
|
23 |
|
24 |
|
25 |
-
#
|
26 |
|
27 |
-
|
28 |
-
You can find some example images below.
|
29 |
|
30 |
-
|
31 |
-
![images_0)](./images_0.png)
|
32 |
-
prompt: Roughness Map
|
33 |
-
![images_1)](./images_1.png)
|
34 |
-
prompt: Roughness Map
|
35 |
-
![images_2)](./images_2.png)
|
36 |
-
prompt: Roughness Map
|
37 |
-
![images_3)](./images_3.png)
|
38 |
|
|
|
|
|
39 |
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
|
|
|
|
42 |
|
43 |
-
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
-
|
|
|
|
|
50 |
|
51 |
-
|
|
|
52 |
|
53 |
-
|
|
|
54 |
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
should probably proofread and complete it, then remove this comment. -->
|
23 |
|
24 |
|
25 |
+
# controlnet_rough
|
26 |
|
27 |
+
Generate a roughness map from a photograph or basecolor (albedo) map.
|
|
|
28 |
|
29 |
+
# Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
```
|
32 |
+
import argparse
|
33 |
|
34 |
+
from PIL import Image
|
35 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
|
36 |
+
from diffusers.utils import load_image
|
37 |
+
import torch
|
38 |
|
39 |
+
parser = argparse.ArgumentParser(description="Args for parser")
|
40 |
+
parser.add_argument("--seed", type=int, default=1, help="Seed for inference")
|
41 |
+
args = parser.parse_args()
|
42 |
|
43 |
+
base_model_path = "stabilityai/stable-diffusion-2-1-base"
|
44 |
+
controlnet_path = "sidnarsipur/controlnet_rough"
|
45 |
|
46 |
+
controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
|
47 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
48 |
+
base_model_path, controlnet=controlnet, torch_dtype=torch.float16
|
49 |
+
)
|
50 |
|
51 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
52 |
+
pipe.enable_xformers_memory_efficient_attention()
|
53 |
+
pipe.enable_model_cpu_offload()
|
54 |
|
55 |
+
control_image = load_image("inference/basecolor.png") #Change based on your image path
|
56 |
+
prompt = "Roughness Map" #Don't change!
|
57 |
|
58 |
+
if control_image.size[0] > 2048 or control_image.size[1] > 2048: #Optional
|
59 |
+
control_image = control_image.resize((control_image.size[0] // 2, control_image.size[1] // 2))
|
60 |
|
61 |
+
generator = torch.manual_seed(args.seed)
|
62 |
+
|
63 |
+
image = pipe(
|
64 |
+
prompt, num_inference_steps=50, generator=generator, image=control_image
|
65 |
+
).images[0]
|
66 |
+
image.save("inference/normal.png")
|
67 |
+
```
|