<s> import glob <EOL> import os <EOL> import numpy as np <EOL> import skimage . io <EOL> directories = glob . glob ( "<STR_LIT>" ) <EOL> class_names = [ os . path . basename ( d ) for d in directories ] <EOL> class_names . sort ( ) <EOL> num_classes = len ( class_names ) <EOL> paths_train = glob . glob ( "<STR_LIT>" ) <EOL> paths_train . sort ( ) <EOL> paths_test = glob . glob ( "<STR_LIT>" ) <EOL> paths_test . sort ( ) <EOL> paths = { <EOL> '<STR_LIT:train>' : paths_train , <EOL> '<STR_LIT:test>' : paths_test , <EOL> } <EOL> labels_train = np . zeros ( len ( paths [ '<STR_LIT:train>' ] ) , dtype = '<STR_LIT>' ) <EOL> for k , path in enumerate ( paths [ '<STR_LIT:train>' ] ) : <EOL> class_name = os . path . basename ( os . path . dirname ( path ) ) <EOL> labels_train [ k ] = class_names . index ( class_name ) <EOL> def load ( subset = '<STR_LIT:train>' ) : <EOL> """<STR_LIT>""" <EOL> images = np . empty ( len ( paths [ subset ] ) , dtype = '<STR_LIT:object>' ) <EOL> for k , path in enumerate ( paths [ subset ] ) : <EOL> img = skimage . io . imread ( path , as_grey = True ) <EOL> images [ k ] = img <EOL> return images <EOL> print "<STR_LIT>" <EOL> np . save ( "<STR_LIT>" , labels_train ) <EOL> print "<STR_LIT>" <EOL> os . system ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> images_train = load ( '<STR_LIT:train>' ) <EOL> print "<STR_LIT>" <EOL> np . save ( "<STR_LIT>" , images_train ) <EOL> del images_train <EOL> print "<STR_LIT>" <EOL> os . system ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> images_test = load ( '<STR_LIT:test>' ) <EOL> np . save ( "<STR_LIT>" , images_test ) <EOL> del images_test <EOL> print "<STR_LIT>" <EOL> os . system ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" </s>
