Skip to content

Commit

Permalink
GAN bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragav Venkatesan committed Jan 18, 2017
1 parent 98ce476 commit 23da23e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pantry/tutorials/gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def simple_gan ( dataset= None, verbose = 1 ):
visualizer_params = {
"root" : '.',
"frequency" : 1,
"sample_size": 144,
"sample_size": 225,
"rgb_filters": False,
"debug_functions" : False,
"debug_layers": True,
Expand Down Expand Up @@ -85,7 +85,7 @@ def simple_gan ( dataset= None, verbose = 1 ):
net.add_layer ( type = "dot_product",
id = "D(x)",
origin = "x",
num_neurons = 512,
num_neurons = 1024,
dropout_rate = 0,
activation = ('maxout','maxout',2),
verbose = verbose
Expand All @@ -97,7 +97,7 @@ def simple_gan ( dataset= None, verbose = 1 ):
id = "D(G(z))",
origin = "G(z)",
dropout_rate = 0,
num_neurons = 512,
num_neurons = 1024,
input_params = net.dropout_layers["D(x)"].params, # must be the same params,
# this way it remains the same network.
activation = ('maxout','maxout',2),
Expand Down Expand Up @@ -168,6 +168,7 @@ def simple_gan ( dataset= None, verbose = 1 ):
from yann.utils.graph import draw_network
draw_network(net.graph, filename = 'gan.png')
net.pretty_print()

net.cook ( objective_layers = ["classifier_obj","real_obj","fake_obj"],
optimizer_params = optimizer_params,
generator_layers = ["G(z)"],
Expand All @@ -177,8 +178,9 @@ def simple_gan ( dataset= None, verbose = 1 ):
verbose = verbose )

learning_rates = (0.05, 0.001, 0.0001)

net.train( epochs = (50, 50),
k = 1, # refer to Ian Goodfellow's paper Algorithm 1.
k = 5, # refer to Ian Goodfellow's paper Algorithm 1.
validate_after_epochs = 1,
training_accuracy = True,
show_progress = True,
Expand Down
8 changes: 6 additions & 2 deletions yann/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ def preprocessing( data, height, width, channels, args):
"GCN" : True for global contrast normalization
"ZCA" : True, kind of like a PCA representation (not fully tested)
"grayscale" : Convert the image to grayscale
"mean_subtract" : Subtracts the mean of the image.
}
Expand All @@ -704,6 +705,7 @@ def preprocessing( data, height, width, channels, args):
GCN = args [ "GCN" ]
ZCA = args [ "ZCA" ]
gray = args [ "grayscale" ]
mean_subtract = args [ "mean_subtract" ]

# Assume that the data is already resized on height and width and all ...
if len(data.shape) == 2 and channels > 1:
Expand Down Expand Up @@ -731,7 +733,8 @@ def preprocessing( data, height, width, channels, args):
data = numpy.reshape(data,out_shp)
if normalize is True or ZCA is True:
data = data / (data.max(axis = 0) + 1e-7)
# do this normalization thing in batch mode.
# do this normalization thing in batch mode.
if mean_subtract is True or ZCA is True:
data = data - data.mean(axis = 0)

if ZCA is True:
Expand Down Expand Up @@ -1195,10 +1198,11 @@ def cook_mnist( verbose = 1,

# parameters relating to preprocessing.
preprocess_params = {
"normalize" : False,
"normalize" : True,
"GCN" : False,
"ZCA" : False,
"grayscale" : False,
"mean_subtract" : False,
}
else:
preprocess_params = kwargs['preprocess_params']
Expand Down

0 comments on commit 23da23e

Please sign in to comment.