Skip to content

Commit 0717a01

Browse files
add biggan test
1 parent 2157b8f commit 0717a01

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

seminar06-style-transfer/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
11
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/yandexdataschool/Practical_DL/blob/spring20/seminar06-style-transfer/style_transfer_pytorch.ipynb)
2+
3+
4+
5+
`to be used in seminar`
6+
7+
```(python)
8+
import multiprocessing as mp
9+
import multiprocessing.shared_memory
10+
import numpy as np
11+
import torch
12+
from pytorch_pretrained_biggan import BigGAN
13+
import matplotlib.pyplot as plt
14+
%matplotlib inline
15+
model = BigGAN.from_pretrained('biggan-deep-128').cuda().eval()
16+
model.cuda();
17+
model();
18+
with torch.no_grad():
19+
20+
z_torch = torch.randn(1, 128)
21+
c_torch = torch.randint(0, 1000, size=[1])
22+
23+
gen_images = model.forward(
24+
z_torch.clamp_(-5, 5).cuda(),
25+
torch.nn.functional.one_hot(c_torch.clamp_(0, 999).cuda(), num_classes=1000).to(torch.float32),
26+
truncation=0.4)
27+
28+
gen_images = torch.clamp((gen_images + 1) / 2, 0, 1)
29+
image = gen_images.data.cpu().numpy()[0].transpose(1, 2, 0)
30+
31+
plt.imshow(image)
32+
```

0 commit comments

Comments
 (0)