Instructions to use RyanHangZhou/PICS with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use RyanHangZhou/PICS 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("RyanHangZhou/PICS", 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
| import torch | |
| from ldm.modules.midas.api import load_midas_transform | |
| class AddMiDaS(object): | |
| def __init__(self, model_type): | |
| super().__init__() | |
| self.transform = load_midas_transform(model_type) | |
| def pt2np(self, x): | |
| x = ((x + 1.0) * .5).detach().cpu().numpy() | |
| return x | |
| def np2pt(self, x): | |
| x = torch.from_numpy(x) * 2 - 1. | |
| return x | |
| def __call__(self, sample): | |
| # sample['jpg'] is tensor hwc in [-1, 1] at this point | |
| x = self.pt2np(sample['jpg']) | |
| x = self.transform({"image": x})["image"] | |
| sample['midas_in'] = x | |
| return sample |