xinsir commited on
Commit
fe9add9
1 Parent(s): edefb24

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +17 -8
README.md CHANGED
@@ -54,10 +54,17 @@ Use the code below to get started with the model.
54
  ```python
55
  from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
56
  from diffusers import DDIMScheduler, EulerAncestralDiscreteScheduler
 
 
 
 
57
  from PIL import Image
58
  import torch
59
  import numpy as np
60
  import cv2
 
 
 
61
 
62
  def HWC3(x):
63
  assert x.dtype == np.uint8
@@ -126,17 +133,19 @@ if random.random() > 0.5:
126
  # Method 1
127
  # if you use hed, you should provide an image, the image can be real or anime, you extract its hed lines and use it as the scribbles
128
  # The detail about hed detect you can refer to https://github.com/lllyasviel/ControlNet/blob/main/gradio_fake_scribble2image.py
129
- # I provide a pseudo-code here
130
- # img = cv2.imread(img_path)
131
- # hed_img = apply_hed(img)
132
- # cv2.imwrite("a hed detect path for an image", hed_img)
133
-
134
- controlnet_img = Image.open("a hed detect path for an image")
 
 
135
  controlnet_img = np.array(controlnet_img)
136
  controlnet_img = nms(controlnet_img, 127, 3)
137
  controlnet_img = cv2.GaussianBlur(controlnet_img, (0, 0), 3)
138
-
139
- # different threshold for different lines
140
  random_val = int(round(random.uniform(0.01, 0.10), 2) * 255)
141
  controlnet_img[controlnet_img > random_val] = 255
142
  controlnet_img[controlnet_img < 255] = 0
 
54
  ```python
55
  from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
56
  from diffusers import DDIMScheduler, EulerAncestralDiscreteScheduler
57
+ from controlnet_aux import PidiNetDetector, HEDdetector
58
+ from diffusers.utils import load_image
59
+ from huggingface_hub import HfApi
60
+ from pathlib import Path
61
  from PIL import Image
62
  import torch
63
  import numpy as np
64
  import cv2
65
+ import os
66
+
67
+
68
 
69
  def HWC3(x):
70
  assert x.dtype == np.uint8
 
133
  # Method 1
134
  # if you use hed, you should provide an image, the image can be real or anime, you extract its hed lines and use it as the scribbles
135
  # The detail about hed detect you can refer to https://github.com/lllyasviel/ControlNet/blob/main/gradio_fake_scribble2image.py
136
+ # Below is a example using diffusers HED detector
137
+
138
+ image_path = Image.open("your image path, the image can be real or anime, HED detector will extract its edge boundery")
139
+ processor = HEDdetector.from_pretrained('lllyasviel/Annotators')
140
+ controlnet_img = processor(image_path, scribble=True)
141
+ controlnet_img.save("a hed detect path for an image")
142
+
143
+ # following is some processing to simulate human sketch draw, different threshold can generate different width of lines
144
  controlnet_img = np.array(controlnet_img)
145
  controlnet_img = nms(controlnet_img, 127, 3)
146
  controlnet_img = cv2.GaussianBlur(controlnet_img, (0, 0), 3)
147
+
148
+ # higher threshold, thiner line
149
  random_val = int(round(random.uniform(0.01, 0.10), 2) * 255)
150
  controlnet_img[controlnet_img > random_val] = 255
151
  controlnet_img[controlnet_img < 255] = 0