Download component.py from gatilin/nld-uni-vision-encoder: direct link, hf CLI and curl.
- Browser
- Download file 933 Bytes
-
https://huggingface.co/gatilin/nld-uni-vision-encoder/resolve/main/component.py
- Command line
-
hf download hf://gatilin/nld-uni-vision-encoder/component.py
-
curl -L -o component.py https://huggingface.co/gatilin/nld-uni-vision-encoder/resolve/main/component.py
933 Bytes
| """Standalone NLD-Uni RADIO visual tower and multimodal projector.""" | |
| import importlib,json,sys,types | |
| from pathlib import Path | |
| import torch | |
| from accelerate import init_empty_weights | |
| from safetensors.torch import load_file | |
| def load_model(root): | |
| root=Path(root).resolve();name='_nld_uni_vision_bundle' | |
| if name not in sys.modules: | |
| package=types.ModuleType(name);package.__path__=[str(root)];sys.modules[name]=package | |
| vision=importlib.import_module(name+'.vision');projector=importlib.import_module(name+'.projector') | |
| config=types.SimpleNamespace(**json.loads((root/'config.json').read_text())) | |
| with init_empty_weights(): | |
| model=torch.nn.Module();model.encoder=torch.nn.Module();model.encoder.vision_tower=vision.RadioVisionTower();model.encoder.mm_projector=projector.RadioHProjector(config) | |
| state=load_file(str(root/'model.safetensors'),device='cpu');model.load_state_dict(state,strict=True,assign=True) | |
| return model.eval() | |