Text-to-Image
Diffusers
Safetensors
StableDiffusionPipeline
stable-diffusion
stable-diffusion-diffusers
textual_inversion
diffusers-training
Instructions to use aiwithi/Story_Generation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use aiwithi/Story_Generation with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.bfloat16, device_map="cuda") pipe.load_textual_inversion("aiwithi/Story_Generation") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Download diffusers/examples/research_projects/anytext/ocr_recog/common.py from aiwithi/Story_Generation: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/aiwithi/Story_Generation/resolve/main/diffusers/examples/research_projects/anytext/ocr_recog/common.py
- Command line
-
hf download hf://aiwithi/Story_Generation/diffusers/examples/research_projects/anytext/ocr_recog/common.py
-
curl -L -o common.py https://huggingface.co/aiwithi/Story_Generation/resolve/main/diffusers/examples/research_projects/anytext/ocr_recog/common.py
2.19 kB
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class Hswish(nn.Module): | |
| def __init__(self, inplace=True): | |
| super(Hswish, self).__init__() | |
| self.inplace = inplace | |
| def forward(self, x): | |
| return x * F.relu6(x + 3.0, inplace=self.inplace) / 6.0 | |
| # out = max(0, min(1, slop*x+offset)) | |
| # paddle.fluid.layers.hard_sigmoid(x, slope=0.2, offset=0.5, name=None) | |
| class Hsigmoid(nn.Module): | |
| def __init__(self, inplace=True): | |
| super(Hsigmoid, self).__init__() | |
| self.inplace = inplace | |
| def forward(self, x): | |
| # torch: F.relu6(x + 3., inplace=self.inplace) / 6. | |
| # paddle: F.relu6(1.2 * x + 3., inplace=self.inplace) / 6. | |
| return F.relu6(1.2 * x + 3.0, inplace=self.inplace) / 6.0 | |
| class GELU(nn.Module): | |
| def __init__(self, inplace=True): | |
| super(GELU, self).__init__() | |
| self.inplace = inplace | |
| def forward(self, x): | |
| return torch.nn.functional.gelu(x) | |
| class Swish(nn.Module): | |
| def __init__(self, inplace=True): | |
| super(Swish, self).__init__() | |
| self.inplace = inplace | |
| def forward(self, x): | |
| if self.inplace: | |
| x.mul_(torch.sigmoid(x)) | |
| return x | |
| else: | |
| return x * torch.sigmoid(x) | |
| class Activation(nn.Module): | |
| def __init__(self, act_type, inplace=True): | |
| super(Activation, self).__init__() | |
| act_type = act_type.lower() | |
| if act_type == "relu": | |
| self.act = nn.ReLU(inplace=inplace) | |
| elif act_type == "relu6": | |
| self.act = nn.ReLU6(inplace=inplace) | |
| elif act_type == "sigmoid": | |
| raise NotImplementedError | |
| elif act_type == "hard_sigmoid": | |
| self.act = Hsigmoid(inplace) | |
| elif act_type == "hard_swish": | |
| self.act = Hswish(inplace=inplace) | |
| elif act_type == "leakyrelu": | |
| self.act = nn.LeakyReLU(inplace=inplace) | |
| elif act_type == "gelu": | |
| self.act = GELU(inplace=inplace) | |
| elif act_type == "swish": | |
| self.act = Swish(inplace=inplace) | |
| else: | |
| raise NotImplementedError | |
| def forward(self, inputs): | |
| return self.act(inputs) | |