forked from p-christ/Generating-Pokemon-Using-a-WGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_functions.py
More file actions
44 lines (38 loc) · 1.41 KB
/
helper_functions.py
File metadata and controls
44 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import tensorflow as tf
import scipy
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import imread
import imageio
def view_samples(epoch, samples, nrows, ncols, figsize=(5,5)):
"""Displays the images that come out of the network"""
fig, axes = plt.subplots(figsize=figsize, nrows=nrows, ncols=ncols,
sharey=True, sharex=True)
for ax, img in zip(axes.flatten(), samples[epoch]):
ax.axis('off')
img = (img + 1.0)/2.0
img = img*255.0
ax.set_adjustable('box-forced')
im = ax.imshow(img, aspect='equal')
plt.subplots_adjust(wspace=0, hspace=0)
return fig, axes
def showImagesHorizontally(list_of_files, height=15, width=15):
"""Show a list of images in a horizontal line.
Args:
list_of_files: a list of paths to png images
height: height you want the images to be
width: width you want the images to be"""
fig = plt.figure()
fig.set_figheight(height)
fig.set_figwidth(width)
number_of_files = len(list_of_files)
for i in range(number_of_files):
a=fig.add_subplot(1,number_of_files,i+1)
image = imageio.imread(list_of_files[i])
plt.imshow(image,cmap='Greys_r')
plt.axis('off')
def lrelu(x):
"""Leaky Relu activation function which is sometimes preferred over
Relu for GANs."""
return tf.maximum(x, tf.multiply(x, 0.2))