huggingface / controlnet_aux

Apache License 2.0
400 stars 86 forks source link

Cannot import name 'Network' from 'controlnet_aux.hed' #66

Open 7231 opened 1 year ago

7231 commented 1 year ago

When I run:

from controlnet_aux.hed import Network  
hed_network = Network(f"{local_fold}/lllyasviel/ControlNet/annotator/ckpts/network-bsds500.pth")
HEDdetector(hed_network)

I got this error:

ImportError: cannot import name 'Network' from 'controlnet_aux.hed'

(I find init.py of "hed" folder has no 'Network' class or function.

moono commented 1 year ago

I think on new version (0.0.6) they have changed pth file. (network-bsds500.pth is gone now ...)

try this,

from controlnet_aux import HEDdetector
from controlnet_aux.hed import ControlNetHED_Apache2

# download the new file via .from_pretrained()
# this will download the file on huggingface cache dir 
# usually ${HOME}/.cache/huggingface/hub/models--lllyasviel--Annotators
hed = HEDdetector.from_pretrained(model_repo)

model_dir = "...."  # <-- find 'ControlNetHED.pth' file's directory from the cache dir
model_path = os.path.join(model_dir, "ControlNetHED.pth")
network = ControlNetHED_Apache2()
network.load_state_dict(torch.load(model_path, map_location="cpu"))
network.float().eval()

hed_detector = HEDdetector(network)

copied from, https://github.com/patrickvonplaten/controlnet_aux/blob/1e6bdc07c88d0358ae3c84862adb043ffd30c27c/src/controlnet_aux/hed/__init__.py#L72