Skip to content

Commit

Permalink
Merge pull request #23 from ragavvenkatesan/dev
Browse files Browse the repository at this point in the history
Updating Master with Dev
  • Loading branch information
Ragav Venkatesan committed Feb 23, 2017
2 parents 69c822f + 826fcb4 commit 8bc44a2
Show file tree
Hide file tree
Showing 24 changed files with 690 additions and 712 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python:
before_install:
- pip install -r requirements_test.txt
- pip install travis-sphinx
- pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git

install:
- python setup.py install
Expand Down
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
from mock import Mock

import theano
import theano.sandbox.cuda
# import theano.sandbox.cuda

theano.config = Mock(device='gpu')
theano.sandbox.cuda.cuda_enabled = True
theano.sandbox.cuda.dnn = Mock(dnn_available=lambda: True)
sys.modules['theano.sandbox.cuda.blas'] = Mock(GpuCorrMM=None)
# theano.sandbox.cuda.cuda_enabled = True
# theano.sandbox.cuda.dnn = Mock(dnn_available=lambda: True)
# sys.modules['theano.sandbox.cuda.blas'] = Mock(GpuCorrMM=None)

import shlex

Expand Down
16 changes: 15 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,23 @@ independently first and then run the above command. Note that this installer, do
of options of the toolbox for which you need to go through the complete install described at the
:ref:`setup` page.

Verify that the installation of theano is indeed version 0.9 or greater by doing the following in
a python shell

.. code-block:: python
import theano
theano.__version__
If the version was not 0.9, you can install 0.9 by doing the following:

.. code-block:: bash
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
The start and the end of Yann toolbox is the :mod:`network` module. The :mod:`yann.network`.
``network`` object is where all the magic happens. Start by importing :mod:`network` and creating a
``network`` object.
``network`` object in a python shell.

.. code-block:: python
Expand Down
14 changes: 14 additions & 0 deletions docs/source/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ If it showed any errors, install ``numpy`` first. ``skdata`` has some issue that
installed first. If you use anaconda, just install the numpy and scipy using ``conda install``
instead of ``pip install``. This will setup the toolbox for all intentions and purposes.

Verify that the installation of theano is indeed version 0.9 or greater by doing the following in
a python shell

.. code-block:: python
import theano
theano.__version__
If the version was not 0.9, you can install 0.9 by doing the following:

.. code-block:: bash
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
For a full-fledged installation procedure, don't do the above but run through the following set of
instructions. If you want to install all other supporting features like datasets, visualizers and
others, do the following:
Expand Down
75 changes: 21 additions & 54 deletions pantry/tutorials/gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def cook_mnist( verbose = 1, **kwargs):
data_params = {
"source" : 'skdata',
"name" : 'mnist',
"location" : '',
"location" : '',
"mini_batch_size" : 100,
"mini_batches_per_batch" : (500, 100, 100),
"batches2train" : 1,
Expand All @@ -47,7 +47,7 @@ def cook_mnist( verbose = 1, **kwargs):
"normalize" : True,
"ZCA" : False,
"grayscale" : False,
"zero_mean" : False,
"zero_mean" : True,
}
else:
preprocess_params = kwargs['preprocess_params']
Expand All @@ -63,7 +63,7 @@ def cook_mnist( verbose = 1, **kwargs):
verbose = 3)
return dataset

def mlgan ( dataset= None, verbose = 1 ):
def shallow_gan ( dataset= None, verbose = 1 ):
"""
This function is a demo example of a generative adversarial network.
This is an example code. You should study this code rather than merely run it.
Expand All @@ -90,7 +90,7 @@ def mlgan ( dataset= None, verbose = 1 ):
visualizer_params = {
"root" : '.',
"frequency" : 1,
"sample_size": 225,
"sample_size": 100,
"rgb_filters": False,
"debug_functions" : False,
"debug_layers": True,
Expand Down Expand Up @@ -128,69 +128,34 @@ def mlgan ( dataset= None, verbose = 1 ):
# the time.
mean_subtract = False )

#G(z) contains params theta_g - 100 X 784 - creates images of 1 X 784
net.add_layer ( type = "dot_product",
origin = "z",
id = "G1",
num_neurons = 1200,
activation = 'relu',
verbose = verbose
)

net.add_layer ( type = "dot_product",
origin = "G1",
id = "G2",
num_neurons = 1200,
activation = 'relu',
verbose = verbose
)

net.add_layer ( type = "dot_product",
origin = "G2",
id = "G(z)",
num_neurons = 784,
activation = 'sigmoid',
activation = 'tanh',
verbose = verbose
) # This layer is the one that creates the images.

#D(x) - Contains params theta_d creates features 1 X 800.
net.add_layer ( type = "dot_product",
id = "D1",
id = "D(x)",
origin = "x",
num_neurons = 1200,
activation = ('maxout','maxout',5),
num_neurons = 800,
activation = 'relu',
regularize = True,
verbose = verbose
)

net.add_layer ( type = "dot_product",
id = "Dz1",
id = "D(G(z))",
origin = "G(z)",
input_params = net.dropout_layers["D1"].params,
num_neurons = 1200,
activation = ('maxout','maxout',5),
input_params = net.dropout_layers["D(x)"].params,
num_neurons = 800,
activation = 'relu',
regularize = True,
verbose = verbose
)

net.add_layer ( type = "dot_product",
id = "D(x)",
origin = "D1",
num_neurons = 1200,
activation = ('maxout','maxout',5),
regularize = True,
verbose = verbose
)

net.add_layer ( type = "dot_product",
id = "D(G(z))",
origin = "Dz1",
input_params = net.dropout_layers["D(x)"].params,
num_neurons = 1200,
activation = ('maxout','maxout',5),
regularize = True,
verbose = verbose
)

#C(D(x)) - This is the opposite of C(D(G(z))), real
net.add_layer ( type = "dot_product",
Expand Down Expand Up @@ -257,16 +222,16 @@ def mlgan ( dataset= None, verbose = 1 ):

net.cook ( objective_layers = ["classifier_obj","real_obj","fake_obj"],
optimizer_params = optimizer_params,
classifier_layers = ["D1", "D(x)", "softmax"],
discriminator_layers = ["D1","D(x)"],
generator_layers = ["G1","G(z)"],
classifier_layers = ["D(x)", "softmax"],
discriminator_layers = ["D(x)"],
generator_layers = ["G(z)"],
softmax_layer = "softmax",
verbose = verbose )

learning_rates = (0.04, 0.001, 0.0001 )
learning_rates = (0.04, 0.01, 0.001 )

net.train( epochs = (50, 50 ),
k = 5,
net.train( epochs = (5, 5 ),
k = 1,
pre_train_discriminator = 0,
validate_after_epochs = 1,
visualize_after_epochs = 1,
Expand All @@ -275,6 +240,8 @@ def mlgan ( dataset= None, verbose = 1 ):
early_terminate = True,
verbose = verbose)

return net

if __name__ == '__main__':
import sys
dataset = None
Expand All @@ -292,4 +259,4 @@ def mlgan ( dataset= None, verbose = 1 ):
data = cook_mnist (verbose = 2)
dataset = data.dataset_location()

mlgan ( dataset, verbose = 2 )
net = shallow_gan ( dataset, verbose = 2 )
40 changes: 20 additions & 20 deletions pantry/tutorials/lenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def lenet5 ( dataset= None, verbose = 1 ):
"""
optimizer_params = {
"momentum_type" : 'polyak',
"momentum_params" : (0.75, 0.97, 30),
"momentum_params" : (0.65, 0.97, 30),
"optimizer_type" : 'adagrad',
"id" : "main"
}
Expand Down Expand Up @@ -100,7 +100,7 @@ def lenet5 ( dataset= None, verbose = 1 ):
id = "dot_product_2",
num_neurons = 1250,
activation = 'relu',
regularize = True,
regularize = True,
verbose = verbose
)

Expand All @@ -118,7 +118,7 @@ def lenet5 ( dataset= None, verbose = 1 ):
origin = "softmax",
objective = "nll",
datastream_origin = 'data',
regularization = (0.000, 0.001),
regularization = (0.0001, 0.0001),
verbose = verbose
)

Expand All @@ -133,7 +133,6 @@ def lenet5 ( dataset= None, verbose = 1 ):
verbose = verbose
)


net.train( epochs = (40, 40 ),
validate_after_epochs = 1,
training_accuracy = True,
Expand All @@ -143,6 +142,7 @@ def lenet5 ( dataset= None, verbose = 1 ):
verbose = verbose)

net.test(verbose = verbose)

# Advaned version of the CNN
def lenet_maxout ( dataset= None, verbose = 1 ):
"""
Expand All @@ -158,7 +158,7 @@ def lenet_maxout ( dataset= None, verbose = 1 ):
"""
optimizer_params = {
"momentum_type" : 'nesterov',
"momentum_params" : (0.5, 0.95, 30),
"momentum_params" : (0.75, 0.95, 30),
"optimizer_type" : 'rmsprop',
"id" : "main"
}
Expand All @@ -175,8 +175,8 @@ def lenet_maxout ( dataset= None, verbose = 1 ):
"frequency" : 1,
"sample_size": 32,
"rgb_filters": True,
"debug_functions" : True,
"debug_layers": True, # Since we are on steroids this time, print everything.
"debug_functions" : False,
"debug_layers": False, # Since we are on steroids this time, print everything.
"id" : 'main'
}

Expand All @@ -198,9 +198,7 @@ def lenet_maxout ( dataset= None, verbose = 1 ):
net.add_layer ( type = "input",
id = "input",
verbose = verbose,
origin = 'data', # if you didnt add a dataset module, now is
# the time.
mean_subtract = False )
origin = 'data' )

net.add_layer ( type = "conv_pool",
origin = "input",
Expand All @@ -223,17 +221,17 @@ def lenet_maxout ( dataset= None, verbose = 1 ):
activation = ('maxout', 'maxout', 2),
batch_norm = True,
regularize = True,
dropout_rate = 0, # because of maxout
verbose = verbose
)

net.add_layer ( type = "dot_product",
origin = "conv_pool_2",
id = "dot_product_1",
num_neurons = 1250,
regularize = True,
activation = ('maxout', 'maxout', 2),
activation = 'relu',
dropout_rate = 0.5,
batch_norm = True,
regularize = True,
verbose = verbose
)

Expand All @@ -242,9 +240,9 @@ def lenet_maxout ( dataset= None, verbose = 1 ):
id = "dot_product_2",
num_neurons = 1250,
activation = 'relu',
batch_norm = True,
dropout_rate = 0.5,
regularize = True,
regularize = True,
batch_norm = True,
verbose = verbose
)

Expand All @@ -260,8 +258,8 @@ def lenet_maxout ( dataset= None, verbose = 1 ):
net.add_layer ( type = "objective",
id = "obj",
origin = "softmax",
objective = "cce",
regularization = (0.000, 0.001),
objective = "nll",
regularization = (0.0001, 0.0001),
datastream_origin = 'data',
verbose = verbose
)
Expand Down Expand Up @@ -304,11 +302,13 @@ def lenet_maxout ( dataset= None, verbose = 1 ):

if dataset is None:
print " creating a new dataset to run through"
from yann.special.datasets import cook_cifar10
data = cook_cifar10 (verbose = 2)
from yann.special.datasets import cook_cifar10
from yann.special.datasets import cook_mnist
# data = cook_cifar10 (verbose = 2)
data = cook_mnist()
dataset = data.dataset_location()

lenet5 ( dataset, verbose = 2 )
# lenet5 ( dataset, verbose = 3 )
lenet_maxout (dataset, verbose = 2)


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='yann',
version='0.0.1a1',
version='0.1.1a1',
description='Toolbox for building and learning convolutional neural networks',
long_description=long_description,
url='https://github.com/ragavvenkatesan/yann',
Expand Down
2 changes: 1 addition & 1 deletion yann/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.0.1a1'
__version__ = '0.1.1a1'

4 changes: 2 additions & 2 deletions yann/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__ ( self,
elif mode == 'max' or mode == 'sum': # normal maxpool
self.out = pool_2d(
input=input,
ds=ds,
ws=ds,
ignore_border = ignore_border,
mode = mode
)
Expand All @@ -97,7 +97,7 @@ def __init__ ( self,
elif mode == 'mean':
self.out = pool_2d(
input=input,
ds=ds,
ws=ds,
ignore_border = ignore_border,
mode = 'average_exc_pad'
)
Expand Down

0 comments on commit 8bc44a2

Please sign in to comment.