Spaces:
Runtime error
Runtime error
Download src/models/sam.py from PAIR/HD-Painter: direct link, hf CLI and curl.
- Browser
- Download file 527 Bytes
-
https://huggingface.co/spaces/PAIR/HD-Painter/resolve/main/src/models/sam.py
- Command line
-
hf download hf://spaces/PAIR/HD-Painter/src/models/sam.py
-
curl -L -o sam.py https://huggingface.co/spaces/PAIR/HD-Painter/resolve/main/src/models/sam.py
527 Bytes
| import torch | |
| from segment_anything import sam_model_registry, SamPredictor | |
| from .common import * | |
| MODEL_PATH = f'{MODEL_FOLDER}/sam/sam_vit_h_4b8939.pth' | |
| DOWNLOAD_URL = 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth' | |
| # pre-download | |
| # download_file(DOWNLOAD_URL, MODEL_PATH) | |
| def load_model(device='cuda:0'): | |
| download_file(DOWNLOAD_URL, MODEL_PATH) | |
| sam = sam_model_registry["vit_h"](checkpoint=MODEL_PATH) | |
| sam.to(device=device) | |
| sam_predictor = SamPredictor(sam) | |
| return sam_predictor | |