Skip to content

Commit 6ae20a3

Browse files
committed
add images to readme
1 parent 2e60033 commit 6ae20a3

File tree

9 files changed

+63
-111
lines changed

9 files changed

+63
-111
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ See the [doc section](#doc) below for details on these classes and methods.
4848

4949
```python
5050
import torch
51-
from pytorch_pretrained_biggan import (BigGAN, one_hot_from_name, truncated_noise_sample,
51+
from pytorch_pretrained_biggan import (BigGAN, one_hot_from_names, truncated_noise_sample,
5252
save_as_images, display_in_terminal)
5353

5454
# OPTIONAL: if you want to have more information on what's happening, activate the logger as follows
@@ -58,26 +58,30 @@ logging.basicConfig(level=logging.INFO)
5858
# Load pre-trained model tokenizer (vocabulary)
5959
model = BigGAN.from_pretrained('biggan-deep-256')
6060

61-
# Prepare a dogball input
61+
# Prepare a input
6262
truncation = 0.4
63-
class_vector = (one_hot_from_name('tennis ball') + one_hot_from_name('chihuahua')) / 2
64-
noise_vector = truncated_noise_sample(truncation=truncation)
63+
class_vector = one_hot_from_names(['soap bubble', 'coffee', 'mushroom'], batch_size=3)
64+
noise_vector = truncated_noise_sample(truncation=truncation, batch_size=3)
6565

6666
# All in tensors
6767
noise_vector = torch.from_numpy(noise_vector)
6868
class_vector = torch.from_numpy(class_vector)
6969

70-
# Generate a dog ball
71-
dogball = model(noise_vector, class_vector, truncation)
72-
73-
# Save results as png images
74-
save_as_images(dogball)
70+
# Generate an image
71+
output = model(noise_vector, class_vector, truncation)
7572

7673
# If you have a sixtel compatible terminal you can display the images in the terminal
7774
# (see https://github.com/saitoha/libsixel for details)
78-
display_in_terminal(dogball)
75+
display_in_terminal(output)
76+
77+
# Save results as png images
78+
save_as_images(output)
7979
```
8080

81+
![output_0](assets/output_0.png)
82+
![output_1](assets/output_1.png)
83+
![output_2](assets/output_2.png)
84+
8185
## Doc
8286

8387
### Loading DeepMind's pre-trained weights
@@ -190,7 +194,7 @@ Here are some details on these methods:
190194
- Output:
191195
- array of shape (batch_size, 1000)
192196

193-
- `one_hot_from_name(class_name, batch_size=1)`:
197+
- `one_hot_from_names(class_name, batch_size=1)`:
194198

195199
Create a one-hot vector from the name of an imagenet class ('tennis ball', 'daisy', ...). We use NLTK's wordnet search to try to find the relevant synset of ImageNet and take the first one. If we can't find it direcly, we look at the hyponyms and hypernyms of the class name.
196200
- Params:

assets/output_0.png

86.6 KB
Loading

assets/output_1.png

93.4 KB
Loading

assets/output_2.png

112 KB
Loading

full_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tensorflow
22
tensorflow-hub
33
Pillow
4-
NLTK
5-
python-libsixel
4+
nltk
5+
libsixel-python

pytorch_pretrained_biggan/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from .file_utils import PYTORCH_PRETRAINED_BIGGAN_CACHE, cached_path
44
from .utils import (truncated_noise_sample, save_as_images,
55
convert_to_images, display_in_terminal,
6-
one_hot_from_int, one_hot_from_name)
6+
one_hot_from_int, one_hot_from_names)

pytorch_pretrained_biggan/imagenet.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

pytorch_pretrained_biggan/model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,8 @@ def forward(self, z, class_label, truncation):
298298

299299
if __name__ == "__main__":
300300
import PIL
301-
from .utils import truncated_noise_sample, save_as_images
301+
from .utils import truncated_noise_sample, save_as_images, one_hot_from_names
302302
from .convert_tf_to_pytorch import load_tf_weights_in_biggan
303-
from .imagenet import one_hot_from_name
304303

305304
load_cache = False
306305
cache_path = './saved_model.pt'
@@ -316,7 +315,7 @@ def forward(self, z, class_label, truncation):
316315

317316
truncation = 0.4
318317
noise = truncated_noise_sample(batch_size=2, truncation=truncation)
319-
label = one_hot_from_name('diver', batch_size=2)
318+
label = one_hot_from_names('diver', batch_size=2)
320319

321320
# Tests
322321
# noise = np.zeros((1, 128))

pytorch_pretrained_biggan/utils.py

Lines changed: 43 additions & 27 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)