Instructions to use wd1511/fast-ldm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use wd1511/fast-ldm with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("wd1511/fast-ldm", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download model/annotator/pidinet/__init__.py from wd1511/fast-ldm: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/wd1511/fast-ldm/resolve/main/model/annotator/pidinet/__init__.py
- Command line
-
hf download hf://wd1511/fast-ldm/model/annotator/pidinet/__init__.py
-
curl -L -o __init__.py https://huggingface.co/wd1511/fast-ldm/resolve/main/model/annotator/pidinet/__init__.py
1.55 kB
| # Pidinet | |
| # https://github.com/hellozhuo/pidinet | |
| import os | |
| import torch | |
| import numpy as np | |
| from einops import rearrange | |
| from annotator.pidinet.model import pidinet | |
| # from annotator.util import annotator_ckpts_path, safe_step | |
| from ..util_1_1 import annotator_ckpts_path, safe_step | |
| class PidiNetDetector: | |
| def __init__(self): | |
| # remote_model_path = "https://huggingface.co/lllyasviel/Annotators/resolve/main/table5_pidinet.pth" | |
| modelpath = os.path.join("./pretrained_models/table5_pidinet.pth") | |
| if not os.path.exists(modelpath): | |
| from basicsr.utils.download_util import load_file_from_url | |
| load_file_from_url(remote_model_path, model_dir=annotator_ckpts_path) | |
| self.netNetwork = pidinet() | |
| self.netNetwork.load_state_dict({k.replace('module.', ''): v for k, v in torch.load(modelpath)['state_dict'].items()}) | |
| self.netNetwork = self.netNetwork.cuda() | |
| self.netNetwork.eval() | |
| def __call__(self, input_image, safe=False): | |
| assert input_image.ndim == 3 | |
| input_image = input_image[:, :, ::-1].copy() | |
| with torch.no_grad(): | |
| image_pidi = torch.from_numpy(input_image).float().cuda() | |
| image_pidi = image_pidi / 255.0 | |
| image_pidi = rearrange(image_pidi, 'h w c -> 1 c h w') | |
| edge = self.netNetwork(image_pidi)[-1] | |
| edge = edge.cpu().numpy() | |
| if safe: | |
| edge = safe_step(edge) | |
| edge = (edge * 255.0).clip(0, 255).astype(np.uint8) | |
| return edge[0][0] | |