Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
7231 opened this issue Jul 21, 2023 · 1 comment
Open

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

7231 opened this issue Jul 21, 2023 · 1 comment

Comments

@7231
Copy link

7231 commented Jul 21, 2023

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
Copy link

moono commented Jul 26, 2023

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

princepride added a commit to princepride/JARVIS that referenced this issue Apr 22, 2024
Grateful for your work! As mentioned in microsoft#233, running from controlnet_aux.hed import Network now raises an error. This is because starting from controlnet_aux version 0.06, the controlnet_aux/hed file has undergone changes.

To address this, I referred to the code provided in huggingface/controlnet_aux#66 and made modifications to the original code accordingly. It's worth noting that the network-bsds500.pth model has also been replaced with ControlNetHED.pth, which can be downloaded from https://huggingface.co/lllyasviel/Annotators.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants