def setup(self, bottom, top):
        """
        Setup data layer according to parameters:

        - voc_dir: path to PASCAL VOC dir (must contain 2010)
        - context_dir: path to PASCAL-Context annotations
        - split: train / val / test
        - randomize: load in random order (default: True)
        - seed: seed for randomization (default: None / current time)

        for PASCAL-Context semantic segmentation.

        example: params = dict(voc_dir="/path/to/PASCAL", split="val")
        """
        # config
        params = eval(self.param_str)
        self.voc_dir = params['voc_dir'] + '/VOC2010'
        self.context_dir = params['context_dir']
        self.split = params['split']
        self.mean = np.array((104.007, 116.669, 122.679), dtype=np.float32)
        self.random = params.get('randomize', True)
        self.seed = params.get('seed', None)

        # load labels and resolve inconsistencies by mapping to full 400 labels
        self.labels_400 = [label.replace(' ','') for idx, label in np.genfromtxt(self.context_dir + '/labels.txt', delimiter=':', dtype=None)]
        self.labels_59 = [label.replace(' ','') for idx, label in np.genfromtxt(self.context_dir + '/59_labels.txt', delimiter=':', dtype=None)]
        for main_label, task_label in zip(('table', 'bedclothes', 'cloth'), ('diningtable', 'bedcloth', 'clothes')):
            self.labels_59[self.labels_59.index(task_label)] = main_label

        # two tops: data and label
        if len(top) != 2:
            raise Exception("Need to define two tops: data and label.")
        # data layers have no bottoms
        if len(bottom) != 0:
            raise Exception("Do not define a bottom.")

        # load indices for images and labels
        split_f  = '{}/ImageSets/Main/{}.txt'.format(self.voc_dir,
                self.split)
        self.indices = open(split_f, 'r').read().splitlines()
        self.idx = 0

        # make eval deterministic
        if 'train' not in self.split:
            self.random = False

        # randomization: seed and pick
        if self.random:
            random.seed(self.seed)
            self.idx = random.randint(0, len(self.indices)-1)
def setup ( self , bottom , top ) : params = eval ( self . param_str ) self . voc_dir = params [ 'voc_dir' ] + '/VOC2010' self . context_dir = params [ 'context_dir' ] self . split = params [ 'split' ] self . mean = np . array ( ( 104.007 , 116.669 , 122.679 ) , dtype = np . float32 ) self . random = params . get ( 'randomize' , True ) self . seed = params . get ( 'seed' , None ) self . labels_400 = [ label . replace ( ' ' , '' ) for idx , label in np . genfromtxt ( self . context_dir + '/labels.txt' , delimiter = ':' , dtype = None ) ] self . labels_59 = [ label . replace ( ' ' , '' ) for idx , label in np . genfromtxt ( self . context_dir + '/59_labels.txt' , delimiter = ':' , dtype = None ) ] for main_label , task_label in zip ( ( 'table' , 'bedclothes' , 'cloth' ) , ( 'diningtable' , 'bedcloth' , 'clothes' ) ) : self . labels_59 [ self . labels_59 . index ( task_label ) ] = main_label if len ( top ) != 2 : raise Exception ( "Need to define two tops: data and label." ) if len ( bottom ) != 0 : raise Exception ( "Do not define a bottom." ) split_f = '{}/ImageSets/Main/{}.txt' . format ( self . voc_dir , self . split ) self . indices = open ( split_f , 'r' ) . read ( ) . splitlines ( ) self . idx = 0 if 'train' not in self . split : self . random = False if self . random : random . seed ( self . seed ) self . idx = random . randint ( 0 , len ( self . indices ) - 1 )
Setup data layer according to parameters:

        - voc_dir: path to PASCAL VOC dir (must contain 2010)
        - context_dir: path to PASCAL-Context annotations
        - split: train / val / test
        - randomize: load in random order (default: True)
        - seed: seed for randomization (default: None / current time)

        for PASCAL-Context semantic segmentation.

        example: params = dict(voc_dir="/path/to/PASCAL", split="val")