<s> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> import os <EOL> import cPickle <EOL> import numpy as np <EOL> import theano <EOL> floatX = theano . config . floatX <EOL> from mozi . utils . utils import get_file , make_one_hot <EOL> from mozi . datasets . dataset import SingleBlock <EOL> class Cifar10 ( SingleBlock ) : <EOL> def __init__ ( self , flatten = False , ** kwargs ) : <EOL> im_dir = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> im_dir = get_file ( fpath = "<STR_LIT>" . format ( im_dir ) , origin = path , untar = True ) <EOL> self . label_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . img_shape = ( <NUM_LIT:3> , <NUM_LIT:32> , <NUM_LIT:32> ) <EOL> self . img_size = np . prod ( self . img_shape ) <EOL> self . n_classes = <NUM_LIT:10> <EOL> fnames = [ '<STR_LIT>' % i for i in range ( <NUM_LIT:1> , <NUM_LIT:6> ) ] + [ '<STR_LIT>' ] <EOL> X = [ ] <EOL> y = [ ] <EOL> for fname in fnames : <EOL> data_path = "<STR_LIT>" . format ( im_dir , fname ) <EOL> with open ( data_path ) as fin : <EOL> data_batch = cPickle . load ( fin ) <EOL> if flatten : <EOL> X . extend ( data_batch [ '<STR_LIT:data>' ] . reshape ( ( len ( data_batch [ '<STR_LIT:data>' ] ) , self . img_size ) ) ) <EOL> else : <EOL> X . extend ( data_batch [ '<STR_LIT:data>' ] . reshape ( ( len ( data_batch [ '<STR_LIT:data>' ] ) , ) + self . img_shape ) ) <EOL> y . extend ( data_batch [ '<STR_LIT>' ] ) <EOL> X_npy = np . array ( X , dtype = floatX ) <EOL> X_npy /= <NUM_LIT> <EOL> y_npy = make_one_hot ( y , onehot_size = self . n_classes ) <EOL> ridx = np . arange ( len ( X_npy ) ) <EOL> np . random . shuffle ( ridx ) <EOL> X_npy = X_npy [ ridx ] <EOL> y_npy = y_npy [ ridx ] <EOL> super ( Cifar10 , self ) . __init__ ( X = X_npy , y = y_npy , ** kwargs ) </s>
