huggingface / controlnet_aux

Apache License 2.0
398 stars 86 forks source link

huggingface_hub.utils._validators.HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name' #3

Open onefish51 opened 1 year ago

onefish51 commented 1 year ago

when I load local ckpt

from controlnet_aux import OpenposeDetector

model = OpenposeDetector.from_pretrained("./diffusers/ControlNet")

a error occurred :

Traceback (most recent call last):
  File "test_controlnet.py", line 105, in <module>
    model = OpenposeDetector.from_pretrained("./diffusers/ControlNet")
  File "/opt/conda/lib/python3.8/site-packages/controlnet_aux/open_pose/__init__.py", line 36, in from_pretrained
    body_model_path = hf_hub_download(pretrained_model_or_path, filename)
  File "/opt/conda/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    validate_repo_id(arg_value)
  File "/opt/conda/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 166, in validate_repo_id
    raise HFValidationError(
huggingface_hub.utils._validators.HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': './diffusers/ControlNet'. Use `repo_type` argument if needed.
jinwonkim93 commented 1 year ago

.from_pretrained downloads from hugginface hub.

try this

open_pose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
onefish51 commented 1 year ago

but I want to use local ckpt, which I downloaded

patrickvonplaten commented 1 year ago

Hey @onefish51,

If you want to load the model locally, you should just do:

from controlnet_aux import OpenposeDetector
from controlnet_aux.open_pose.body import Body

body_model = Body("./diffusers/ControlNet/annotator/ckpts/body_pose_model.pth")
detector = OpenposeDetector(body_model)
depyronick commented 1 year ago

https://github.com/huggingface/huggingface_hub/blob/f471a5bac0552d30f75d67b150443cae3d544b77/src/huggingface_hub/utils/_validators.py#L159

    if repo_id.count("/") > 1:
        raise HFValidationError(
            "Repo id must be in the form 'repo_name' or 'namespace/repo_name':"
            f" '{repo_id}'. Use `repo_type` argument if needed."
        )
patrickvonplaten commented 1 year ago

Hey @depyronick,

Could you maybe open a new issue with a reproducible error message?

depyronick commented 1 year ago

Hey @depyronick,

Could you maybe open a new issue with a reproducible error message?

huggingface_hub module raises an error if pretrained_model_or_path has more than one / in it. because of that we cannot use from_pretrained methods for specifying local paths.

your previous example works, but it's the case for all other type of nets.

e.g. for scribble should also use (instead from_pretrained):

network_model = Network('./controlnets/net/annotator/ckpts/network-bsds500.pth')
hed = HEDdetector(network_model)
image = hed(image, scribble=True)

i've no issue on this, just a reminder for future explorers.