yamildiego commited on
Commit
2391a94
·
1 Parent(s): 0d2eb1f

added canny

Browse files
Files changed (1) hide show
  1. handler.py +13 -13
handler.py CHANGED
@@ -91,15 +91,15 @@ class EndpointHandler():
91
 
92
 
93
  controlnet_pose_model = "thibaud/controlnet-openpose-sdxl-1.0"
94
- # controlnet_canny_model = "diffusers/controlnet-canny-sdxl-1.0"
95
  # controlnet_depth_model = "diffusers/controlnet-depth-sdxl-1.0-small"
96
 
97
  controlnet_pose = ControlNetModel.from_pretrained(
98
  controlnet_pose_model, torch_dtype=dtype
99
  ).to(device)
100
- # controlnet_canny = ControlNetModel.from_pretrained(
101
- # controlnet_canny_model, torch_dtype=dtype
102
- # ).to(device)
103
  # controlnet_depth = ControlNetModel.from_pretrained(
104
  # controlnet_depth_model, torch_dtype=dtype
105
  # ).to(device)
@@ -107,10 +107,10 @@ class EndpointHandler():
107
  openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
108
  # depth_anything = DepthAnything.from_pretrained('LiheYoung/depth_anything_vitl14').to(device).eval()
109
 
110
- # def get_canny_image(image, t1=100, t2=200):
111
- # image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
112
- # edges = cv2.Canny(image, t1, t2)
113
- # return Image.fromarray(edges, "L")
114
 
115
  # def get_depth_map(image):
116
 
@@ -135,13 +135,13 @@ class EndpointHandler():
135
 
136
  self.controlnet_map = {
137
  "pose": controlnet_pose,
138
- # "canny": controlnet_canny,
139
  # "depth": controlnet_depth,
140
  }
141
 
142
  self.controlnet_map_fn = {
143
  "pose": openpose,
144
- # "canny": get_canny_image,
145
  # "depth": get_depth_map,
146
  }
147
 
@@ -152,12 +152,13 @@ class EndpointHandler():
152
 
153
  identitynet_strength_ratio = 0.8
154
  pose_strength = 0.4
155
- self.my_controlnet_selection = ["pose"]
 
156
 
157
 
158
  controlnet_scales = {
159
  "pose": pose_strength,
160
- # "canny": canny_strength,
161
  # "depth": depth_strength,
162
  }
163
  self.pipe.controlnet = MultiControlNetModel(
@@ -184,7 +185,6 @@ class EndpointHandler():
184
  pose_image_path = data.pop("pose_image_path", "https://i.ibb.co/9bP9tMb/pose-2-1.jpg")
185
 
186
  adapter_strength_ratio = 0.8
187
- # canny_strength = 0.3
188
  # depth_strength = 0.5
189
  # controlnet_selection = ["pose", "canny", "depth"]
190
 
 
91
 
92
 
93
  controlnet_pose_model = "thibaud/controlnet-openpose-sdxl-1.0"
94
+ controlnet_canny_model = "diffusers/controlnet-canny-sdxl-1.0"
95
  # controlnet_depth_model = "diffusers/controlnet-depth-sdxl-1.0-small"
96
 
97
  controlnet_pose = ControlNetModel.from_pretrained(
98
  controlnet_pose_model, torch_dtype=dtype
99
  ).to(device)
100
+ controlnet_canny = ControlNetModel.from_pretrained(
101
+ controlnet_canny_model, torch_dtype=dtype
102
+ ).to(device)
103
  # controlnet_depth = ControlNetModel.from_pretrained(
104
  # controlnet_depth_model, torch_dtype=dtype
105
  # ).to(device)
 
107
  openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
108
  # depth_anything = DepthAnything.from_pretrained('LiheYoung/depth_anything_vitl14').to(device).eval()
109
 
110
+ def get_canny_image(image, t1=100, t2=200):
111
+ image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
112
+ edges = cv2.Canny(image, t1, t2)
113
+ return Image.fromarray(edges, "L")
114
 
115
  # def get_depth_map(image):
116
 
 
135
 
136
  self.controlnet_map = {
137
  "pose": controlnet_pose,
138
+ "canny": controlnet_canny,
139
  # "depth": controlnet_depth,
140
  }
141
 
142
  self.controlnet_map_fn = {
143
  "pose": openpose,
144
+ "canny": get_canny_image,
145
  # "depth": get_depth_map,
146
  }
147
 
 
152
 
153
  identitynet_strength_ratio = 0.8
154
  pose_strength = 0.4
155
+ canny_strength = 0.3
156
+ self.my_controlnet_selection = ["pose", "canny"]
157
 
158
 
159
  controlnet_scales = {
160
  "pose": pose_strength,
161
+ "canny": canny_strength,
162
  # "depth": depth_strength,
163
  }
164
  self.pipe.controlnet = MultiControlNetModel(
 
185
  pose_image_path = data.pop("pose_image_path", "https://i.ibb.co/9bP9tMb/pose-2-1.jpg")
186
 
187
  adapter_strength_ratio = 0.8
 
188
  # depth_strength = 0.5
189
  # controlnet_selection = ["pose", "canny", "depth"]
190