Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add unet effnetb7 #66

Merged
merged 5 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Emojich.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,24 @@ show(pil_images, 4)
```
![](./pics/emojich/emoji-Donald.png)

### Super Resolution:
```python
from rudalle.pipelines import super_resolution
from rudalle import get_realesrgan

device = 'cuda'
realesrgan = get_realesrgan('x4', device=device)
sr_images = super_resolution(pil_images, realesrgan)
```

### Converting to Telegram Stickers format (512x512 RGBA)
Also, don't forget you can use super resolution before :)
```python
from rudalle.pipelines import convert_emoji_to_rgba, show_rgba
from rudalle import get_emojich_unet

device = 'cuda'
emojich_unet = get_emojich_unet('unet_effnetb5').to(device)
rgba_images = convert_emoji_to_rgba(pil_images, emojich_unet, device=device)
emojich_unet = get_emojich_unet('unet_effnetb7').to(device)
rgba_images = convert_emoji_to_rgba(sr_images, emojich_unet, device=device)
for rgba_image in rgba_images:
show_rgba(rgba_image);
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sberbank-ai/ru-dalle/master.svg)](https://results.pre-commit.ci/latest/github/sberbank-ai/ru-dalle/master)

```
pip install rudalle==0.2.1
pip install rudalle==0.3.0
```
### 🤗 HF Models:
[ruDALL-E Malevich (XL)](https://huggingface.co/sberbank-ai/rudalle-Malevich) \
Expand Down
2 changes: 1 addition & 1 deletion rudalle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
'image_prompts',
]

__version__ = '0.2.1'
__version__ = '0.3.0'
13 changes: 12 additions & 1 deletion rudalle/emojich_unet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import torch
import segmentation_models_pytorch as smp
from huggingface_hub import hf_hub_url, cached_download


Expand All @@ -12,12 +11,24 @@
repo_id='sberbank-ai/rudalle-Emojich',
filename='pytorch_model.bin',
),
'unet_effnetb7': dict(
encoder_name='efficientnet-b7',
repo_id='sberbank-ai/rudalle-Emojich',
filename='pytorch_model.bin',
),
}


def get_emojich_unet(name, cache_dir='/tmp/rudalle'):
assert name in MODELS
config = MODELS[name]
try:
import segmentation_models_pytorch as smp
except ImportError:
import logging
logging.warning('If you would like to use emojich_unet, you should reinstall timm package:'
'"pip install timm==0.4.12"')
return
model = smp.Unet(
encoder_name=config['encoder_name'],
encoder_weights=None,
Expand Down
2 changes: 1 addition & 1 deletion rudalle/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def show(pil_images, nrow=4, size=14, save_dir=None, show=True):
plt.show()


def convert_emoji_to_rgba(pil_images, emojich_unet, device='cpu', bs=4):
def convert_emoji_to_rgba(pil_images, emojich_unet, device='cpu', bs=1):
final_images = []
with torch.no_grad():
for chunk in more_itertools.chunked(pil_images, bs):
Expand Down