Download patch_annotators.py from atatakun/ControlNet-v1-1-Annotators-cpu: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/atatakun/ControlNet-v1-1-Annotators-cpu/resolve/main/patch_annotators.py
- Command line
-
hf download hf://spaces/atatakun/ControlNet-v1-1-Annotators-cpu/patch_annotators.py
-
curl -L -o patch_annotators.py https://huggingface.co/spaces/atatakun/ControlNet-v1-1-Annotators-cpu/resolve/main/patch_annotators.py
1.54 kB
| """ | |
| patch_annotators.py | |
| =================== | |
| annotator ๅ ใฎไบๆๆงๅ้กใใฉใณใฟใคใ ใงใใใใใใขใธใฅใผใซใ | |
| app.py ใฎๅ้ ญใง import ใใใ ใใงๆๅนใซใชใใพใใ | |
| ๅฏพๅฟใใๅ้ก: | |
| 1. annotator/zoe/__init__.py: torch.load ใซ strict=False ใๅฟ ่ฆ | |
| (timm ใฎใใผใธใงใณใขใใใง relative_position_index ใญใผใๆถใใใใ) | |
| """ | |
| import importlib | |
| import sys | |
| from unittest.mock import patch | |
| # โโ Zoe: torch.load ใ strict=False ใงใฉใใ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| def _patch_zoe(): | |
| """ | |
| annotator.zoe.__init__ ใฎ ZoeDetector.__init__ ใ | |
| model.load_state_dict(...) ใ strict=True (ใใใฉใซใ) ใงๅผใถใฎใ | |
| strict=False ใซๅทฎใๆฟใใใ | |
| """ | |
| try: | |
| import torch | |
| _original_load_state_dict = torch.nn.Module.load_state_dict | |
| def _patched_load_state_dict(self, state_dict, strict=True, **kwargs): | |
| # ZoeDepth ใขใใซใฎใญใผใๆใ ใ strict=False ใซ็ทฉใใ | |
| cls_name = type(self).__name__ | |
| if cls_name == "ZoeDepth": | |
| strict = False | |
| return _original_load_state_dict(self, state_dict, strict=strict, **kwargs) | |
| torch.nn.Module.load_state_dict = _patched_load_state_dict | |
| print("[patch_annotators] Patched: ZoeDepth.load_state_dict -> strict=False") | |
| except Exception as e: | |
| print(f"[patch_annotators] Warning: Could not patch ZoeDepth: {e}") | |
| _patch_zoe() | |