Giter Site home page Giter Site logo

tariqdaouda / mariana Goto Github PK

View Code? Open in Web Editor NEW
151.0 12.0 32.0 25.25 MB

The Cutest Deep Learning Framework which is also a wonderful Declarative Language

Home Page: http://www.tariqdaouda.com

License: Apache License 2.0

Python 37.67% Makefile 1.25% Batchfile 1.22% HTML 0.24% JavaScript 47.24% CSS 0.06% Jupyter Notebook 12.33%
python machine-learning machine-learning-algorithms machinelearning deep-learning deep-neural-networks deeplearning deep-learning-library deep-learning-algorithms artificial-intelligence

mariana's Introduction

What will happen now that Theano is no longer developed?

Mariana works! I still use it almost everyday.

I am still taking care of the maintenance and may still add some minor features. For the future, the most straightforward path would be a complete port to Tensorflow or PyTorch. Let me know if you'd like to help!

T .

image

logo by Sawssan Kaddoura.

Mariana V1 is here

MARIANA: The Cutest Deep Learning Framework

image

MARIANA V2.

Mariana is meant to be a efficient language through which complex deep neural networks can be easily expressed and easily manipulated. It's simple enough for beginners and doesn't get much complicated. Intuitive, user-friendly and yet flexible enough for research. It's here to empower researchers, teachers and students alike, while greatly facilitating AI knowledge transfer into other domains.

Mariana is also compatible with google's GPUs and colab. For a running basic example you can check here on colab.

import Mariana.layers as ML
import Mariana.scenari as MS
import Mariana.costs as MC
import Mariana.activations as MA
import Mariana.regularizations as MR

import Mariana.settings as MSET

ls = MS.GradientDescent(lr = 0.01, momentum=0.9)
cost = MC.NegativeLogLikelihood()

inp = ML.Input(28*28, name = "InputLayer")
h1 = ML.Hidden(300, activation = MA.ReLU(), name = "Hidden1", regularizations = [ MR.L1(0.0001) ])
h2 = ML.Hidden(300, activation = MA.ReLU(), name = "Hidden2", regularizations = [ MR.L1(0.0001) ])
o = ML.SoftmaxClassifier(10, learningScenari = [ls], cost = cost, name = "Probabilities")

#Connecting layers
inp > h1 > h2
concat = ML.C([inp, h2])

MLP_skip = concat > o
MLP_skip.init()

#Visualizing
MLP_skip.saveHTML("mySkipMLP")

    #training:
for i in xrange(1000) :
    MLP_skip["Probabilities"].train({"InputLayer.inputs": train_set[0], "Probabilities.targets": train_set[1]})

#testing
    print MLP_skip["Probabilities"].test({"InputLayer.inputs": test_set[0], "Probabilities.targets": test_set[1]})

V2's most exciting stuff

V2 is almost a complete rewite of V1. It is much better.

What's done

  • New built-in visualization: Interactive visuallization that shows architecture along with parameters, hyper-parameters as well as user defined notes. A great tool for collaboration.
  • Function mixins (my favorite): Mariana functions can now be added together! The result is a function that performs the actions of all its components at once. Let's say we have two output layers and want a function that optimises on losses for both outputs. Creating it is as simple as: f = out1.train + out2.train, and then calling f. Mariana will derive f from both functions adding the costs, calculating gradients and updates seemlessly in the background
  • Easy access to gradients and updates: Just call .getGradients(), .getUpdates() on any function to get a view of either gradients of updates for all parameters.
  • User friendly error messages: Functions will tell you what arguments they expect.
  • Very very clean code with Streams!: You probably heard of batchnorm... and how it has a different behaviour in training and in testing. Well that simple fact can be the cause of some very messy DL code. With streams all this is over. Streams are parallel universes of execution for functions. You can define your own streams and have as many as you want. For batchnorm it mean that depending on the stream you call your function in (test or train), the behaviour will be different, even though you only changed one word.
  • Chainable optimization rules: As in the previous version, layers inherit their learning scenari from outputs, but have the possibility to redifine them. This is still true, but rules can now be chained. Here's how to define a layer with fixed bias: l = Dense( learningScenari=[GradientDescent(lr = 0.1), Fixed('b')])
  • Just in time function compilation: All functions (including mixins) are only compiled if needed.
  • Lasagne compatible: Every lasagne layer can be seemlessly imported and used into Mariana
  • Convolutions, Deconvolutions (Transpose convolution), all sorts of convolutions...
  • Much easier to extend: The (almost) complete rewrite made for a much more cleaner code that is much more easy to extend. It is now much simpler to create your own layers, decorators, etc... Function that you need to implement end with _abs and Mariana has whole new bunch of custom type that support streams.
  • New merge layer: Need a layer that is a linear combination of other layers? The new MergeLayer is perfect for that newLayer = M(layer1 + (layers3 * layer3) + 4 )
  • New concatenation layer: newLayer = C([Layer1, layer2])
  • Unlimited number of inputs per layer: Each layer used to be limited to one. Now it is infinit
  • Abstractions are now divided into trainable (layers, decorators, activations) and untrainable (scenari, costs, initializations): All trainable abstractions can hold parameters and have untrainable abstractions applied to them. PReLU will finally join ReLU as an activation!
  • Fancy ways to go downhill: Adam, Adagrad, ...

What's almost done

  • Inclusion of popular recurrences (LSTM, recurent layers, ...)

What's next

  • Complete refactorisation of training encapsulation. Training encapsulation was the least popular aspect of Mariana so far. I will completely rewrite it to give it the same level of intuitiveness as the rest of the framework. The next iterration will be a huge improvement.
  • Arbitrary recurrences in the graph

mariana's People

Contributors

jonathanseguin avatar logan169 avatar tariqdaouda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mariana's Issues

Problems with loaded model

Hello again @tariqdaouda,

Looks like I am facing a challenge here hehe.

What I am trying to do is actually use the already trained model in my system.

So I trained my model with the parameters I experimented to get me the best results and your trainer saved the parameters into the pkl file.

To load the model I used the code in the documentation:
`import cPickle

mlp = cPickle.load(open("myMLP.mariana.pkl"))

But mlp is a dict object, don't have the propagate function.

So I looked it up in the code and found the LoadModel method. I tried to load the model with the following code:

mlp_state = MN.loadModel("mlp_state/state-config")

Worked! Now I have the method propagate. To get the output layer result, I used this code (from test.py in the repository):

o = mlp_state.outputs.values()[0] mlp_state.classify(o, inp = numpy.asarray(inputSet))
But first I was getting an error that the dimensions of the input are wrong:
TypeError: ('Bad input argument to theano function with name "/media/guilhermevrs/Data/Documentos/Academico/TCC-code/Mariana/Mariana/wrappers.py:58" at index 1(0-based)', 'Wrong number of dimensions: expected 2, got 1 with shape (42,).')

My input is of 42 nodes. I even trained the model with 42.

So I placed my input data as the first element of an array. Now the error I am getting this one:

TypeError: Tried to provide value for implicit input: <TensorType(float64, matrix)>

Can you give me a light here, please?

Training function output (cost) is affected by L1/L2 regularization

  • L1 or L2 @ 0.0
Epoch 0
    Train score: 0.735989272594
    Validation score: 0.718354940414 +best+
  • L1 or L2 @ 0.01
Epoch 0
    Train score: 0.915873587132
    Validation score: 0.704464316368 +best+
  • L1 or L2 @ 0.1
Epoch 0
    Train score: 2.71569609642
    Validation score: 0.699838221073 +best+
  • L1 or L2 @ 1.0
Epoch 0
    Train score: 20.8013763428
    Validation score: 0.702481269836 +best+

Improve model visualization

The current version shows layer connectivity but not the hyper-parameters values. An improved visualization that contains information about hyper-parameters would allow the sharing of an entire model through a visual and small HTML file.

Decorators malfunction

Decorators may not be applied to layers. This issue has been fixed in dev branch and will be part of the next merge.

Error with neural network training example

Hello,

I am facing a problem when I start my trainer and I can't figure out the cause.

My input data is of dimension 42 and my output should be one value out of 4.

This is the shape of my training and test set:

Training set: 
input = (1152, 42) target = (1152,)

Training set: input = (1152, 42) target = (1152,)
Test set: input = (384, 42) target = (384,)

This is the construction of my network:

ls = MS.GradientDescent(lr=0.01)
cost = MC.CrossEntropy()

i = ML.Input(42, name='inp')
h = ML.Hidden(23, activation=MA.Sigmoid(), initializations=[MI.GlorotTanhInit()], name="hid")
o = ML.SoftmaxClassifier(4, learningScenario=ls, costObject=cost, name="out")

mlp = i > h > o

And this is the construction of the datasets, trainers and recorders:

trainData = MDM.RandomSeries(distances = train_set[0], next_state = train_set[1])
trainMaps = MDM.DatasetMapper()
trainMaps.mapInput(i, trainData.distances)
trainMaps.mapOutput(o, trainData.next_state)

testData = MDM.RandomSeries(distances = test_set[0], next_state = test_set[1])
testMaps = MDM.DatasetMapper()
testMaps.mapInput(i, testData.distances)
testMaps.mapOutput(o, testData.next_state)

earlyStop = MSTOP.GeometricEarlyStopping(testMaps, patience=100, patienceIncreaseFactor=1.1, significantImprovement=0.00001, outputFunction="score", outputLayer=o)
epochWall = MSTOP.EpochWall(1000)

trainer = MT.DefaultTrainer(
        trainMaps=trainMaps,
        testMaps=testMaps,
        validationMaps=None,
        stopCriteria=[earlyStop, epochWall],
        testFunctionName="testAndAccuracy",
        trainMiniBatchSize=MT.DefaultTrainer.ALL_SET,
        saveIfMurdered=False
    )

recorder = MREC.GGPlot2("MLP", whenToSave = [MREC.SaveMin("test", o.name, "score")], printRate=1, writeRate=1)

trainer.start("MLP", mlp, recorder = recorder)

But the following error is being produced:

Traceback (most recent call last):
  File "nn-mariana.py", line 82, in <module>
    trainer.start("MLP", mlp, recorder = recorder)
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 226, in start
    Trainer_ABC.start( self, runName, model, recorder, trainingOrder, moreHyperParameters )
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 110, in start
    return self.run(runName, model, recorder, *args, **kwargs)
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 410, in run
    outputLayers
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 269, in _trainTest
    res = modelFct(output, **kwargs)
  File "SUPRESSED/Mariana/Mariana/network.py", line 47, in __call__
    return self.callTheanoFct(outputLayer, **kwargs)
  File "SUPRESSED/Mariana/Mariana/network.py", line 44, in callTheanoFct
    return self.outputFcts[ol](**kwargs)
  File "SUPRESSED/Mariana/Mariana/wrappers.py", line 110, in __call__
    return self.run(**kwargs)
  File "SUPRESSED/Mariana/Mariana/wrappers.py", line 102, in run
    fres = iter(self.theano_fct(*self.fctInputs.values()))
  File "SUPRESSED/Theano/theano/compile/function_module.py", line 871, in __call__
    storage_map=getattr(self.fn, 'storage_map', None))
  File "SUPRESSED/Theano/theano/gof/link.py", line 314, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File "SUPRESSED/Theano/theano/compile/function_module.py", line 859, in __call__
    outputs = self.fn()
ValueError: Input dimension mis-match. (input[0].shape[1] = 1152, input[1].shape[1] = 4)
Apply node that caused the error: Elemwise{Composite{((i0 * i1) + (i2 * log(i3)))}}[(0, 1)](InplaceDimShuffle{x,0}.0, LogSoftmax.0, Elemwise{sub,no_inplace}.0, Elemwise{sub,no_inplace}.0)
Toposort index: 18
Inputs types: [TensorType(int32, row), TensorType(float64, matrix), TensorType(int32, row), TensorType(float64, matrix)]
Inputs shapes: [(1, 1152), (1152, 4), (1, 1152), (1152, 4)]
Inputs strides: [(4608, 4), (32, 8), (4608, 4), (32, 8)]
Inputs values: ['not shown', 'not shown', 'not shown', 'not shown']
Outputs clients: [[Sum{axis=[1], acc_dtype=float64}(Elemwise{Composite{((i0 * i1) + (i2 * log(i3)))}}[(0, 1)].0)]]

Versions:

Mariana (1.0.1rc1, /media/guilhermevrs/Data/Documentos/Academico/TCC-code/Mariana)
Theano (0.8.0.dev0, SUPRESSED/Theano)

This code was produced having as base the tutorial code from the mnist example.

Could you please help me to figure out what's going on?

Thank you in advance

Score or Accuracy?

Hello @tariqdaouda,

First of all, thank you for this framework. It works very well!

I was wondering how does exactly work every observation made during the training phase.

I mean, supposing I am interested in getting the percentage error of my network on a given test set. What data should I look in this case?

Thank you in advance

TypeError using Bionomial Dropout decorator

Training crashes with TypeError when using Binomial Dropout.

  File "mlp.py", line 94, in train
    res_train = mlp.train(o, inp=list(train_set['expressions']), target=train_set['class'])
  File "build/bdist.linux-x86_64/egg/Mariana/network.py", line 202, in __getattribute__
  File "build/bdist.linux-x86_64/egg/Mariana/network.py", line 129, in init
  File "build/bdist.linux-x86_64/egg/Mariana/layers.py", line 384, in _setTheanoFunctions
  File "build/bdist.linux-x86_64/egg/Mariana/wrappers.py", line 51, in __init__
  File "/u/seguinj/repos/gvhd-ml/lib/python2.7/site-packages/Theano-0.7.0-py2.7.egg/theano/compile/function.py", line 310, in function
    output_keys=output_keys)
  File "/u/seguinj/repos/gvhd-ml/lib/python2.7/site-packages/Theano-0.7.0-py2.7.egg/theano/compile/pfunc.py", line 499, in pfunc
    no_default_updates=no_default_updates)
  File "/u/seguinj/repos/gvhd-ml/lib/python2.7/site-packages/Theano-0.7.0-py2.7.egg/theano/compile/pfunc.py", line 215, in rebuild_collect_shared
    raise TypeError(err_msg, err_sug)
TypeError: ('An update must have the same type as the original shared variable (shared_var=<CudaNdarrayType(float32, matrix)>, shared_var.type=CudaNdarrayType(float32, matrix), update_val=Softmax.0, update_val.type=TensorType(float64, matrix)).', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')

Composite layer broken

Composite layer is broken and may disappear in the future to be replaced by an automatic layer concatenation.

Saving of huge models

Using save() on models with many layers may crash due to pickle limitations. This is also true for the auto-saves performed by the trainer and the recorder. It will be fixed in the upcoming version.

TypeError: MaxAndArgmax needs a constant axis + NameError: global name 'EndOfTraining' is not defined

ubgpu@ubgpu:~/github/Mariana$ sudo python Mariana/examples/mnist_mlp.py
Using gpu device 0: GeForce GTX 970

|/| /-\ |-> | /-\ || /->

Run device:

I will use the [-GPU-] to run function 'train' of layer 'out'!

Cheers :),

Mariana

Run device:

I will use the [-GPU-] to run function 'test' of layer 'out'!

Cheers :),

Mariana

Run device:

I will use the [-GPU-] to run function 'propagate' of layer 'out'!

Cheers :),

Mariana

ERROR (theano.gof.opt): Optimization failure due to: local_argmax_pushdown
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/theano/gof/opt.py", line 1493, in process_node
replacements = lopt.transform(node)
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/nnet/nnet.py", line 1448, in local_argmax_pushdown
return tensor._max_and_argmax(pre_x, axis)
File "/usr/local/lib/python2.7/dist-packages/theano/gof/op.py", line 507, in call
node = self.make_node(_inputs, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/basic.py", line 1252, in make_node
raise TypeError("MaxAndArgmax needs a constant axis")
TypeError: MaxAndArgmax needs a constant axis

ERROR (theano.gof.opt): Optimization failure due to: local_argmax_pushdown
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/theano/gof/opt.py", line 1493, in process_node
replacements = lopt.transform(node)
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/nnet/nnet.py", line 1454, in local_argmax_pushdown
('x', 0))(pre_bias), axis)
File "/usr/local/lib/python2.7/dist-packages/theano/gof/op.py", line 507, in call
node = self.make_node(_inputs, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/basic.py", line 1252, in make_node
raise TypeError("MaxAndArgmax needs a constant axis")
TypeError: MaxAndArgmax needs a constant axis

==>rec: ggplot2, commit 1, pid: 14344:
|-test set
|->out: 1.62696 +best+
|-train set
|->out: 1.96462 +best+
|-validation set
|->out: 1.61709 +best+

==>rec: ggplot2, commit 2, pid: 14344:
|-test set
|->out: 1.48826 +best+
|-train set
|->out: 1.5747 +best+
|-validation set
|->out: 1.48133 +best+

==>rec: ggplot2, commit 3, pid: 14344:
|-test set
|->out: 1.38383 +best+


==>rec: ggplot2, commit 1001, pid: 14344:
|-test set
|->out: 0.119731 +best+
|-train set
|->out: 0.0630581 +best+
|-validation set
|->out: 0.124834 (best: 0.124825 @ commit: 974)

Dying gracefully from NameError, and saving myself to:

...dx-xb_MLP_death_by_NameError_Sat_Jun_13_21:45:02_2015

Traceback (most recent call last):
File "Mariana/examples/mnist_mlp.py", line 74, in
trainer.start("MLP", mlp)
File "/home/ubgpu/github/Mariana/Mariana/training/trainers.py", line 195, in start
Trainer_ABC.start( self, runName, model, recorder, trainingOrder, shuffle, datasetName )
File "/home/ubgpu/github/Mariana/Mariana/training/trainers.py", line 103, in start
return self.run(runName, model, recorder, _args, *_kwargs)
File "/home/ubgpu/github/Mariana/Mariana/training/trainers.py", line 340, in run
raise EndOfTraining(crit)
NameError: global name 'EndOfTraining' is not defined
ubgpu@ubgpu:~/github/Mariana$ git remote -v

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.