<s> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> import os <EOL> import numpy as np <EOL> import theano <EOL> from mozi . utils . mnist_utils import read_mnist_images , read_mnist_labels , get_mnist_file <EOL> from mozi . datasets . dataset import SingleBlock , DataBlocks <EOL> class Mnist ( SingleBlock ) : <EOL> def __init__ ( self , binary = True , ** kwargs ) : <EOL> im_dir = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> url = '<STR_LIT>' <EOL> paths = [ ] <EOL> for fname in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] : <EOL> path = get_mnist_file ( '<STR_LIT>' . format ( im_dir , fname ) , origin = '<STR_LIT>' . format ( url , fname ) ) <EOL> paths . append ( path ) <EOL> train_X = read_mnist_images ( paths [ <NUM_LIT:0> ] , dtype = '<STR_LIT>' ) <EOL> train_y = read_mnist_labels ( paths [ <NUM_LIT:1> ] ) <EOL> test_X = read_mnist_images ( paths [ <NUM_LIT:2> ] , dtype = '<STR_LIT>' ) <EOL> test_y = read_mnist_labels ( paths [ <NUM_LIT:3> ] ) <EOL> train_X = train_X . reshape ( train_X . shape [ <NUM_LIT:0> ] , train_X . shape [ <NUM_LIT:1> ] * train_X . shape [ <NUM_LIT:2> ] ) <EOL> test_X = test_X . reshape ( test_X . shape [ <NUM_LIT:0> ] , test_X . shape [ <NUM_LIT:1> ] * test_X . shape [ <NUM_LIT:2> ] ) <EOL> X = np . concatenate ( ( train_X , test_X ) , axis = <NUM_LIT:0> ) <EOL> train_y_tmp = np . zeros ( ( train_X . shape [ <NUM_LIT:0> ] , <NUM_LIT:10> ) , dtype = theano . config . floatX ) <EOL> test_y_tmp = np . zeros ( ( test_X . shape [ <NUM_LIT:0> ] , <NUM_LIT:10> ) , dtype = theano . config . floatX ) <EOL> for i in xrange ( train_X . shape [ <NUM_LIT:0> ] ) : <EOL> train_y_tmp [ i , train_y [ i ] ] = <NUM_LIT:1> <EOL> for i in xrange ( test_X . shape [ <NUM_LIT:0> ] ) : <EOL> test_y_tmp [ i , test_y [ i ] ] = <NUM_LIT:1> <EOL> train_y = train_y_tmp <EOL> test_y = test_y_tmp <EOL> if binary : <EOL> X = ( X >= <NUM_LIT:0.5> ) . astype ( int ) <EOL> y = np . concatenate ( ( train_y , test_y ) , axis = <NUM_LIT:0> ) <EOL> super ( Mnist , self ) . __init__ ( X = X , y = y , ** kwargs ) </s>
