MakiPan commited on
Commit
9e7c3db
·
1 Parent(s): 006dceb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -60
app.py CHANGED
@@ -216,66 +216,6 @@ def infer(prompt, negative_prompt, image, model_type="Standard"):
216
  with gr.Blocks(theme='gradio/soft') as demo:
217
  gr.Markdown("## Stable Diffusion with Hand Control")
218
  gr.Markdown("This model is a ControlNet model using MediaPipe hand landmarks for control.")
219
-
220
- gr.Markdown("""<center><h1>Summary</h1></center>
221
-
222
- As Stable diffusion and other diffusion models are notoriously poor at generating realistic hands for our project we decided to train a ControlNet model using MediaPipes landmarks in order to generate more realistic hands avoiding common issues such as unrealistic positions and irregular digits.
223
- <br>
224
- We opted to use the [HAnd Gesture Recognition Image Dataset](https://github.com/hukenovs/hagrid) (HaGRID) and [MediaPipe's Hand Landmarker](https://developers.google.com/mediapipe/solutions/vision/hand_landmarker) to train a control net that could potentially be used independently or as an in-painting tool.
225
- <br>
226
- To preprocess the data there were three options we considered:
227
- - The first was to use Mediapipes built-in draw landmarks function. This was an obvious first choice however we noticed with low training steps that the model couldn't easily distinguish handedness and would often generate the wrong hand for the conditioning image.<center>
228
- <table><tr>
229
- <td>
230
- <p align="center" style="padding: 10px">
231
- <img alt="Forwarding" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/image/image.jpg" width="300">
232
- <br>
233
- <em style="color: grey">Original Image</em>
234
- </p>
235
- </td>
236
- <td>
237
- <p align="center">
238
- <img alt="Routing" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/conditioning_image/image.jpg" width="300">
239
- <br>
240
- <em style="color: grey">Conditioning Image</em>
241
- </p>
242
- </td>
243
- </tr></table>
244
- </center>
245
-
246
- - To counter this issue we changed the palm landmark colours with the intention to keep the color similar in order to learn that they provide similar information, but different to make the model know which hands were left or right.<center>
247
- <table><tr>
248
- <td>
249
- <p align="center" style="padding: 10px">
250
- <img alt="Forwarding" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid-hand-enc-250k/--/MakiPan--hagrid-hand-enc-250k/train/96/image/image.jpg" width="300">
251
- <br>
252
- <em style="color: grey">Original Image</em>
253
- </p>
254
- </td>
255
- <td>
256
- <p align="center">
257
- <img alt="Routing" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid-hand-enc-250k/--/MakiPan--hagrid-hand-enc-250k/train/96/conditioning_image/image.jpg" width="300">
258
- <br>
259
- <em style="color: grey">Conditioning Image</em>
260
- </p>
261
- </td>
262
- </tr></table>
263
- </center>
264
-
265
- - The last option was to use [MediaPipe Holistic](https://ai.googleblog.com/2020/12/mediapipe-holistic-simultaneous-face.html) to provide pose face and hand landmarks to the ControlNet. This method was promising in theory, however, the HaGRID dataset was not suitable for this method as the Holistic model performs poorly with partial body and obscurely cropped images.
266
-
267
- We anecdotally determined that when trained at lower steps the encoded hand model performed better than the standard MediaPipe model due to implied handedness. We theorize that with a larger dataset of more full-body hand and pose classifications, Holistic landmarks will provide the best images in the future however for the moment the hand encoded model performs best. """)
268
-
269
- gr.Markdown("""<center><h2><b>LINKS 🔗</b></h2>
270
- <h3 style="text-align: center;"><a href="https://huggingface.co/Vincent-luo/controlnet-hands">Standard Model Link</a></h3>
271
- <h3 style="text-align: center;"> <a href="https://huggingface.co/MakiPan/controlnet-encoded-hands-130k/">Model using Hand Encoding</a></h3>
272
-
273
- <h3 style="text-align: center;"> <a href="https://huggingface.co/datasets/MakiPan/hagrid250k-blip2">Dataset Used To Train the Standard Model</a></h3>
274
- <h3 style="text-align: center;"> <a href="https://huggingface.co/datasets/MakiPan/hagrid-hand-enc-250k">Dataset Used To Train the Hand Encoding Model</a></h3>
275
-
276
- <h3 style="text-align: center;"> <a href="https://github.com/Maki-DS/Jax-Controlnet-hand-training/blob/main/normal-preprocessing.py">Standard Data Preprocessing Script</a></h3>
277
- <h3 style="text-align: center;"> <a href="https://github.com/Maki-DS/Jax-Controlnet-hand-training/blob/main/Hand-encoded-preprocessing.py">Hand Encoding Data Preprocessing Script</a></h3></center>""")
278
-
279
  model_type = gr.Radio(["Standard", "Hand Encoding"], value="Standard", label="Model preprocessing", info="We developed two models, one with standard MediaPipe landmarks, and one with different (but similar) coloring on palm landmarks to distinguish left and right")
280
 
281
  with gr.Row():
@@ -327,5 +267,70 @@ We anecdotally determined that when trained at lower steps the encoded hand mode
327
 
328
  inputs = [prompt_input, negative_prompt, input_image, model_type]
329
  submit_btn.click(fn=infer, inputs=inputs, outputs=[output_image])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
  demo.launch()
 
216
  with gr.Blocks(theme='gradio/soft') as demo:
217
  gr.Markdown("## Stable Diffusion with Hand Control")
218
  gr.Markdown("This model is a ControlNet model using MediaPipe hand landmarks for control.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  model_type = gr.Radio(["Standard", "Hand Encoding"], value="Standard", label="Model preprocessing", info="We developed two models, one with standard MediaPipe landmarks, and one with different (but similar) coloring on palm landmarks to distinguish left and right")
220
 
221
  with gr.Row():
 
267
 
268
  inputs = [prompt_input, negative_prompt, input_image, model_type]
269
  submit_btn.click(fn=infer, inputs=inputs, outputs=[output_image])
270
+
271
+ gr.Markdown("""
272
+ <center><h1>Summary</h1></center>
273
+
274
+ As Stable diffusion and other diffusion models are notoriously poor at generating realistic hands for our project we decided to train a ControlNet model using MediaPipes landmarks in order to generate more realistic hands avoiding common issues such as unrealistic positions and irregular digits.
275
+ <br>
276
+ We opted to use the [HAnd Gesture Recognition Image Dataset](https://github.com/hukenovs/hagrid) (HaGRID) and [MediaPipe's Hand Landmarker](https://developers.google.com/mediapipe/solutions/vision/hand_landmarker) to train a control net that could potentially be used independently or as an in-painting tool.
277
+ <br>
278
+ To preprocess the data there were three options we considered:
279
+ <br>
280
+ -The first was to use Mediapipes built-in draw landmarks function. This was an obvious first choice however we noticed with low training steps that the model couldn't easily distinguish handedness and would often generate the wrong hand for the conditioning image.<center>
281
+ <br>
282
+ <table><tr>
283
+ <td>
284
+ <p align="center" style="padding: 10px">
285
+ <img alt="Forwarding" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/image/image.jpg" width="300">
286
+ <br>
287
+ <em style="color: grey">Original Image</em>
288
+ </p>
289
+ </td>
290
+ <td>
291
+ <p align="center">
292
+ <img alt="Routing" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/conditioning_image/image.jpg" width="300">
293
+ <br>
294
+ <em style="color: grey">Conditioning Image</em>
295
+ </p>
296
+ </td>
297
+ </tr></table>
298
+ </center>
299
+ <br>
300
+ -To counter this issue we changed the palm landmark colors with the intention to keep the color similar in order to learn that they provide similar information, but different to make the model know which hands were left or right.<center>
301
+ <br>
302
+ <table><tr>
303
+ <td>
304
+ <p align="center" style="padding: 10px">
305
+ <img alt="Forwarding" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid-hand-enc-250k/--/MakiPan--hagrid-hand-enc-250k/train/96/image/image.jpg" width="300">
306
+ <br>
307
+ <em style="color: grey">Original Image</em>
308
+ </p>
309
+ </td>
310
+ <td>
311
+ <p align="center">
312
+ <img alt="Routing" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid-hand-enc-250k/--/MakiPan--hagrid-hand-enc-250k/train/96/conditioning_image/image.jpg" width="300">
313
+ <br>
314
+ <em style="color: grey">Conditioning Image</em>
315
+ </p>
316
+ </td>
317
+ </tr></table>
318
+ </center>
319
+ <br>
320
+ -The last option was to use [MediaPipe Holistic](https://ai.googleblog.com/2020/12/mediapipe-holistic-simultaneous-face.html) to provide pose face and hand landmarks to the ControlNet. This method was promising in theory, however, the HaGRID dataset was not suitable for this method as the Holistic model performs poorly with partial body and obscurely cropped images.
321
+ <br>
322
+ We anecdotally determined that when trained at lower steps the encoded hand model performed better than the standard MediaPipe model due to implied handedness. We theorize that with a larger dataset of more full-body hand and pose classifications, Holistic landmarks will provide the best images in the future however for the moment the hand encoded model performs best. """)
323
+
324
+ gr.Markdown("""
325
+ <center><h2><b>LINKS 🔗</b></h2>
326
+ <h3 style="text-align: center;"><a href="https://huggingface.co/Vincent-luo/controlnet-hands">Standard Model Link</a></h3>
327
+ <h3 style="text-align: center;"> <a href="https://huggingface.co/MakiPan/controlnet-encoded-hands-130k/">Model using Hand Encoding</a></h3>
328
+ <br>
329
+ <h3 style="text-align: center;"> <a href="https://huggingface.co/datasets/MakiPan/hagrid250k-blip2">Dataset Used To Train the Standard Model</a></h3>
330
+ <h3 style="text-align: center;"> <a href="https://huggingface.co/datasets/MakiPan/hagrid-hand-enc-250k">Dataset Used To Train the Hand Encoding Model</a></h3>
331
+ <br>
332
+ <h3 style="text-align: center;"> <a href="https://github.com/Maki-DS/Jax-Controlnet-hand-training/blob/main/normal-preprocessing.py">Standard Data Preprocessing Script</a></h3>
333
+ <h3 style="text-align: center;"> <a href="https://github.com/Maki-DS/Jax-Controlnet-hand-training/blob/main/Hand-encoded-preprocessing.py">Hand Encoding Data Preprocessing Script</a></h3></center>
334
+ """)
335
 
336
  demo.launch()