Coder Social home page Coder Social logo

lasagnetrainer's Introduction

lasagneTrainer

Some code around training a deep neural network created with the lasagne framework Basically, one has to define the network, theano-functions for training and iterators that provide the data.

First steps

Easiest access is the NetworkTrainer.doTraining() function which works without iterators

trainer = NetworkTrainer(some_lasagne_net)
trainer.doTraining(Xtrain, Ytrain, Xval, Yval, train_function, val_function, epochs, batchsize)
trainer.plot_error()

Xtrain, Ytrain, Xval, Yval are just np.ndarrays of samples/labels. train_function, val_function are the functions that calculate training/validation error and update parameters (see DNN_constfunctions.py for a simple cross entropy example)

The iterator interface

A lot more sophisticated things can be done when data is provided via iterators/generators (e.g. on the fly preprocessing, such as rotating).

  1. Create two functions (one for training, one for validation), which take two input arguments and create a generator which returns tuples (X,y).
n = 50
X = np.random.rand(n,3,100,100)  # a couple of 100x100 RGB images
y = np.random.rand(n)>0.5  # some labels

def generator_factory(ix_x, ix_y):
    yield X[ix_x], y[ix_y]
  1. Call NetworkTrainer.do_training_with_generators()
train_ix = np.arange(40)
val_ix = np.arange(40,50)
trainer.do_training_with_generators(generator_factory, generator_factory, trainInput=train_ix, valInput=val_ix)

In each epoch, generator_factory is called with the sample indices (train_ix while training) and iterates over all the samples contained within

TODO

  • add a concrete, workable example

lasagnetrainer's People

Contributors

redst4r avatar

Watchers

 avatar  avatar

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.