<s> from mozi . utils . utils import get_file , make_one_hot <EOL> from mozi . datasets . dataset import SingleBlock <EOL> import xml . etree . ElementTree as ET <EOL> import os <EOL> import glob <EOL> from skimage . transform import resize <EOL> from skimage . io import imread <EOL> import cPickle <EOL> import marshal <EOL> import numpy as np <EOL> class VOC ( SingleBlock ) : <EOL> def __init__ ( self , resized_shape = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , ** kwargs ) : <EOL> '''<STR_LIT>''' <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> actls = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> X_path = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> y_path = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> if not os . path . exists ( X_path ) or not os . path . exists ( y_path ) : <EOL> print X_path + '<STR_LIT>' <EOL> annote = im_dir + '<STR_LIT>' <EOL> images = im_dir + '<STR_LIT>' <EOL> files = glob . glob ( annote + '<STR_LIT>' ) <EOL> labels = [ ] <EOL> rimage = [ ] <EOL> for f in files : <EOL> bname = os . path . basename ( f ) . rstrip ( '<STR_LIT>' ) <EOL> image = imread ( '<STR_LIT>' . format ( images , bname ) ) <EOL> rimage . append ( resize ( image , resized_shape ) ) <EOL> tree = ET . parse ( f ) <EOL> root = tree . getroot ( ) <EOL> actions = root . find ( '<STR_LIT:object>' ) . find ( '<STR_LIT>' ) <EOL> for act in actions : <EOL> if act . text == '<STR_LIT:1>' : <EOL> labels . append ( actls . index ( act . tag ) ) <EOL> break <EOL> print '<STR_LIT>' <EOL> with open ( X_path , '<STR_LIT:wb>' ) as Xout , open ( y_path , '<STR_LIT:wb>' ) as yout : <EOL> X = np . asarray ( rimage ) <EOL> y = np . asarray ( labels ) <EOL> np . save ( Xout , X ) <EOL> np . save ( yout , y ) <EOL> else : <EOL> print X_path + '<STR_LIT>' <EOL> with open ( X_path , '<STR_LIT:rb>' ) as Xin , open ( y_path , '<STR_LIT:rb>' ) as yin : <EOL> X = np . load ( Xin ) <EOL> y = np . load ( yin ) <EOL> super ( VOC , self ) . __init__ ( X = np . rollaxis ( X , <NUM_LIT:3> , <NUM_LIT:1> ) , y = make_one_hot ( y , len ( actls ) ) , ** kwargs ) </s>
