vumichien commited on
Commit
0d3cbf7
Β·
1 Parent(s): 304c89a
Files changed (1) hide show
  1. app.py +76 -64
app.py CHANGED
@@ -216,71 +216,83 @@ 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
- gr.Markdown("""
220
- <style>
221
- ul {padding-left: 5em;}
222
- </style>
223
- <center><h1>Summary</h1></center>
224
-
225
- 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.
226
- <br>
227
- 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.
228
- To preprocess the data there were three options we considered:
229
- <ul>
230
- <li>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.</li>
231
- <center>
232
- <table><tr>
233
- <td>
234
- <p align="center" style="padding: 10px">
235
- <img alt="Forwarding" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/image/image.jpg" width="200">
236
  <br>
237
- <em style="color: grey">Original Image</em>
238
- </p>
239
- </td>
240
- <td>
241
- <p align="center">
242
- <img alt="Routing" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/conditioning_image/image.jpg" width="200">
243
- <br>
244
- <em style="color: grey">Conditioning Image</em>
245
- </p>
246
- </td>
247
- </tr></table>
248
- </center>
249
- <li>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.</li>
250
- <center>
251
- <table><tr>
252
- <td>
253
- <p align="center" style="padding: 10px">
254
- <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="200">
255
- <br>
256
- <em style="color: grey">Original Image</em>
257
- </p>
258
- </td>
259
- <td>
260
- <p align="center">
261
- <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="200">
262
- <br>
263
- <em style="color: grey">Conditioning Image</em>
264
- </p>
265
- </td>
266
- </tr></table>
267
- </center>
268
- <li>The last option was to use <a href="https://ai.googleblog.com/2020/12/mediapipe-holistic-simultaneous-face.html">MediaPipe Holistic</a> 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.</li>
269
- </ul>
270
- 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.
271
- """)
272
- gr.Markdown("""
273
- <center><h2><b>LINKS πŸ”—</b></h2>
274
- <h3 style="text-align: center;">Models πŸš€</h3>
275
- <h4 style="text-align: center;"><a href="https://huggingface.co/Vincent-luo/controlnet-hands">Standard Model</a></h4>
276
- <h4 style="text-align: center;"> <a href="https://huggingface.co/MakiPan/controlnet-encoded-hands-130k/">Model using Hand Encoding</a></h4>
277
- <h3 style="text-align: center;">Datasets πŸ’Ύ</h3>
278
- <h4 style="text-align: center;"> <a href="https://huggingface.co/datasets/MakiPan/hagrid250k-blip2">Dataset for Standard Model</a></h4>
279
- <h4 style="text-align: center;"> <a href="https://huggingface.co/datasets/MakiPan/hagrid-hand-enc-250k">Dataset for Hand Encoding Model</a></h4>
280
- <h3 style="text-align: center;">Preprocessing Scripts πŸ“‘</h3>
281
- <h4 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></h4>
282
- <h4 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></h4></center>
283
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  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")
285
 
286
  with gr.Row():
 
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
+ with gr.Box():
220
+ gr.Markdown("""
221
+ <style>
222
+ ul {padding-left: 5em;}
223
+ </style>
224
+ <center><h1>Summary</h1></center>
225
+
226
+ 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.
 
 
 
 
 
 
 
 
 
227
  <br>
228
+ 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.
229
+ To preprocess the data there were three options we considered:
230
+ <ul>
231
+ <li>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.</li>
232
+ <center>
233
+ <table><tr>
234
+ <td>
235
+ <p align="center" style="padding: 10px">
236
+ <img alt="Forwarding" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/image/image.jpg" width="200">
237
+ <br>
238
+ <em style="color: grey">Original Image</em>
239
+ </p>
240
+ </td>
241
+ <td>
242
+ <p align="center">
243
+ <img alt="Routing" src="https://datasets-server.huggingface.co/assets/MakiPan/hagrid250k-blip2/--/MakiPan--hagrid250k-blip2/train/29/conditioning_image/image.jpg" width="200">
244
+ <br>
245
+ <em style="color: grey">Conditioning Image</em>
246
+ </p>
247
+ </td>
248
+ </tr></table>
249
+ </center>
250
+ <li>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.</li>
251
+ <center>
252
+ <table><tr>
253
+ <td>
254
+ <p align="center" style="padding: 10px">
255
+ <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="200">
256
+ <br>
257
+ <em style="color: grey">Original Image</em>
258
+ </p>
259
+ </td>
260
+ <td>
261
+ <p align="center">
262
+ <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="200">
263
+ <br>
264
+ <em style="color: grey">Conditioning Image</em>
265
+ </p>
266
+ </td>
267
+ </tr></table>
268
+ </center>
269
+ <li>The last option was to use <a href="https://ai.googleblog.com/2020/12/mediapipe-holistic-simultaneous-face.html">MediaPipe Holistic</a> 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.</li>
270
+ </ul>
271
+ 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.
272
+ """)
273
+
274
+ # Information links
275
+ with gr.Box():
276
+ gr.Markdown("""<h2><b>LINKS πŸ”—</b></h2>""")
277
+ with gr.Accordion("Models πŸš€", open=False):
278
+ gr.Markdown("""
279
+ <h4><a href="https://huggingface.co/Vincent-luo/controlnet-hands">Standard Model</a></h4>
280
+ <h4> <a href="https://huggingface.co/MakiPan/controlnet-encoded-hands-130k/">Model using Hand Encoding</a></h4>
281
+ """)
282
+
283
+ with gr.Accordion("Datasets πŸ’Ύ", open=False):
284
+ gr.Markdown("""
285
+ <h4> <a href="https://huggingface.co/datasets/MakiPan/hagrid250k-blip2">Dataset for Standard Model</a></h4>
286
+ <h4> <a href="https://huggingface.co/datasets/MakiPan/hagrid-hand-enc-250k">Dataset for Hand Encoding Model</a></h4>
287
+ """)
288
+
289
+ with gr.Accordion("Preprocessing Scripts πŸ“‘", open=False):
290
+ gr.Markdown("""
291
+ <h4> <a href="https://github.com/Maki-DS/Jax-Controlnet-hand-training/blob/main/normal-preprocessing.py">Standard Data Preprocessing Script</a></h4>
292
+ <h4> <a href="https://github.com/Maki-DS/Jax-Controlnet-hand-training/blob/main/Hand-encoded-preprocessing.py">Hand Encoding Data Preprocessing Script</a></h4></center>
293
+ """)
294
+
295
+ # Model input parameters
296
  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")
297
 
298
  with gr.Row():