{ "metadata": { "name": "TEST_theano_lenet" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import theanoml\n", "reload(theanoml)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 1, "text": [ "" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "## load data - MNIST\n", "import cPickle\n", "X, y = cPickle.load(open('data/digits.pkl', 'rb'))\n", "print X.shape, y.shape" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "(42000, 784) (42000,)\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "import theanoml\n", "reload(theanoml.lenet)\n", "reload(theanoml.formula)\n", "clf = theanoml.lenet.LeNetClassifier(image_size=(28,28), n_classes=10)\n", "clf.fit(X[:5000], y[:5000])\n", "print clf.score(X[:1000], y[:1000])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "epoch 1, minibatch 5 / 8, validation error 73.600000 %\n", "epoch 2, minibatch 2 / 8, validation error 45.800000 %" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "epoch 2, minibatch 7 / 8, validation error 47.600000 %" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "optimization complete with best valiation error 45.800000 %" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "0.645" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "The prediction() in LeNetClassifierFormula does NOT look right\n" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "## Load data - blackbox\n", "import cPickle\n", "import numpy as np\n", "import math\n", "X, y = cPickle.load(open('data/blackbox.pkl', 'rb'))\n", "y = y - 1\n", "X = X[:, :43*43]\n", "classes = np.unique(y)\n", "print X.shape, math.sqrt(X.shape[1]), y.shape, classes\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "(1000, 1849) 43.0 (1000,) [0 1 2 3 4 5 6 7 8]\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "import theanoml\n", "reload(theanoml.lenet)\n", "reload(theanoml.formula)\n", "clf = theanoml.lenet.LeNetClassifier(image_size=(43,43), n_classes=len(classes), batch_size=15)\n", "clf.partial_fit(X, y)\n", "print clf.score(X, y)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "epoch 1, minibatch 5 / 53, validation error 86.153846 %\n", "epoch 1, minibatch 10 / 53, validation error 79.487179 %" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "epoch 1, minibatch 15 / 53, validation error 79.487179 %" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "optimization complete with best valiation error 79.487179 %" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "0.0" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }