Instructions to use sigmoidneuron123/AIupscaling with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use sigmoidneuron123/AIupscaling 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("sigmoidneuron123/AIupscaling", 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.py from sigmoidneuron123/AIupscaling: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/sigmoidneuron123/AIupscaling/resolve/main/model.py
- Command line
-
hf download hf://sigmoidneuron123/AIupscaling/model.py
-
curl -L -o model.py https://huggingface.co/sigmoidneuron123/AIupscaling/resolve/main/model.py
2.04 kB
| from torch import nn | |
| from transformers import PreTrainedModel | |
| from transformers import PretrainedConfig | |
| from torchvision import transforms | |
| from transformers.models.auto.configuration_auto import CONFIG_MAPPING | |
| from transformers.models.auto.modeling_auto import MODEL_MAPPING | |
| class ImageToImageConfig(PretrainedConfig): | |
| model_type = "upscaleing" | |
| def __init__(self, in_channels=3, out_channels=3,in_resolution=256,out_resolution=768, **kwargs): | |
| super().__init__(**kwargs) | |
| self.in_channels = in_channels | |
| self.out_channels = out_channels | |
| self.in_resolution = in_resolution | |
| self.out_resolution = out_resolution | |
| class ImageToImageModel(PreTrainedModel): | |
| config_class = ImageToImageConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.model = nn.Sequential( | |
| nn.Conv2d(in_channels=config.in_channels, out_channels=64, kernel_size=5, padding=2), | |
| nn.ReLU(), | |
| nn.Conv2d(in_channels=64, out_channels=32, kernel_size=3, padding=1), | |
| nn.ReLU(), | |
| nn.Conv2d(in_channels=32, out_channels=3 * 3 * 3, kernel_size=3, padding=1), | |
| nn.PixelShuffle(3) | |
| ) | |
| self.transform1 = transforms.Compose( | |
| transforms=( | |
| transforms.Resize((config.in_resolution,config.in_resolution)), | |
| transforms.ToTensor() | |
| ) | |
| ) | |
| self.transform2 = transforms.Compose( | |
| transforms=( | |
| transforms.ToPILImage(), | |
| transforms.Resize((config.out_resolution,config.out_resolution)) | |
| ) | |
| ) | |
| def forward(self, image): | |
| x = self.transform1(image) | |
| x = self.model(x) | |
| x = self.transform2(x) | |
| return x | |
| CONFIG_MAPPING.register("upscaleing", ImageToImageConfig) | |
| MODEL_MAPPING.register(ImageToImageConfig, ImageToImageModel) | |
| config = ImageToImageConfig() | |
| model = ImageToImageModel(config) | |
| model.save_pretrained("AIupscaleing") | |