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

added cyclegan model #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Binary file added images/cyclegan_cezanne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions nicolalandro_cyclegan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
layout: hub_detail
background-class: hub-background
body-class: hub
category: researchers
title: cyclegan
summary: generate pictures as famous artis from photos
image: cyclegan_cezanne.png
author: Nicola Landro
tags: [vision, generative]
github-link: https://github.com/nicolalandro/cyclegan-pretrained
github-id: nicolalandro/cyclegan-pretrained
featured_image_1: cyclegan_cezanne.png
featured_image_2: no-image
accelerator: "cuda-optional"
---

```python
import torch
model = torch.hub.load('nicolalandro/cyclegan-pretrained', 'cyclegan', pretrained='img2cezanne', device='cpu')
print(model.trained_models_list)
```

### Example Usage

```python
from torchvision import transforms
import torch
import urllib
from PIL import Image
from torchvision.utils import save_image


model = torch.hub.load('nicolalandro/cyclegan-pretrained', 'cyclegan', pretrained='img2cezanne', device='cpu')
model.eval()

url = 'https://raw.githubusercontent.com/nicolalandro/cyclegan-pretrained/main/images/scala_madonnina_del_mare.jpeg'
img = Image.open(urllib.request.urlopen(url))
scale_factor = 0.8
shape = [int(x * scale_factor) for x in img.size]

transform = transforms.Compose([
transforms.Resize(size=(shape[0], shape[1])),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])

scaled_img = transform(img)
torch_images = scaled_img.unsqueeze(0)

with torch.no_grad():
fake_A = 0.5 * (model(torch_images).data + 1.0)
save_image(fake_A, 'cezanne_generated.png')
```

### Model Description
This is a cyclegan, a generative model that is trained on an image style and can trasnform the generic images into images with that particular style.