Mikubill / sd-webui-controlnet

WebUI extension for ControlNet
GNU General Public License v3.0
16.8k stars 1.93k forks source link

[Enhancement] Change HandRefiner Hand Detection model to Yolov8 #2429

Open zcatharisis opened 8 months ago

zcatharisis commented 8 months ago

As per https://huggingface.co/hr16/ControlNet-HandRefiner-pruned/discussions/3, you don't actually need to make an openpose stick figure to get the depthmap. All you need is some reliable way of detecting hands, be it through mediapipe, openpose or boundingbox (yolov8, adetailer's hand model).

Currently, the HandRefiner process uses mediapipe (hrnetv2_w64_imagenet_pretrained.pth), a 500MB file, and inferences using it are long. By changing to Yolov8 hands.pt (taken from Adetailer Extension and is only 20MB), the hand detection processes is comparatively instantaneous, with (hypothetically, needs testing) equal reliability.

Currently, users may change the model from mediapipe to Yolov8 through the following steps:

  1. Go to sd.webui\webui\models\adetailer and copy hand_yolov8s.pt to sd.webui\webui\extensions\sd-webui-controlnet\annotator\downloads\hand_refiner\hr16\ControlNet-HandRefiner-pruned
  2. move hrnetv2_w64_imagenet_pretrained.pth to a different directory (or delete it).
  3. Rename hand_yolov8s.pt to hrnetv2_w64_imagenet_pretrained.pth NOTE: yes you are renaming the pt file to a pth one. This doesn't affect anything apparently.

The only benefit this enhancement provides is a small speed and efficiency boost, not an increase in the reliability of hand detections or depthmap outputs. Understandably, this may be low in priority.

zcatharisis commented 8 months ago

Ran into two issues with the hack above:

  1. A hash verification check prevents the replaced pth file from being read and the preprocessor from executing.
  2. Solving the above issue by using -disable-safe-unpickle in the commandline options makes you vulnerable to attacks, on top of the preprocessor not running anyway due to the ultralytics module not being installed.

At first, I didn't run into these issues because I replaced the file while A1111 was already running. Now, I only recommend doing the above while A1111 is running, and only if you run into out of memory errors while using handrefiner.

sdbds commented 8 months ago

2261 you can test yolo-x