def __init__(self, params): self.batch_size = params['batch_size'] self.outshape = params['shape'] self.classes_per_batch = params['classes_per_batch'] self.img_lmdb = lmdbs(params['img_source']) if params['skt_source'].endswith('.pkl'): self.skt_lmdb = svgs(params['skt_source']) else: self.skt_lmdb = lmdbs(params['skt_source']) self.img_labels = self.img_lmdb.get_label_list() self.skt_labels = self.skt_lmdb.get_label_list() self.img_mean = biproto2py(params['mean_file']).squeeze() self.num_classes = len(set(self.skt_labels)) assert len(self.skt_labels)%self.num_classes==0, \ 'Unequal sketch training samples for each class' self.skt_per_class = len(self.skt_labels) / self.num_classes if 'hard_pos' in params: self.hard_sel = 'hard_pos' self.hard_sel_file = params['hard_pos'] elif 'hard_neg' in params: self.hard_sel = 'hard_neg' self.hard_sel_file = params['hard_neg'] elif 'hard_pn' in params: self.hard_sel = 'hard_pn' self.hard_sel_file = params['hard_pn'] else: assert False, 'Hard selection must be on' self.watchChange = WatchDog( self.hard_sel_file) #check if file has been updated self.hardsel_tab = np.load(self.hard_sel_file) self.hard_pos = self.hardsel_tab['pos'] self.hard_neg = self.hardsel_tab['neg'] self.img_labels_dict, self.classes = vec2dic(self.img_labels) self.NSKTS = len(self.skt_labels) self.indexlist = range(self.NSKTS) self.shuffle_keeping_min_classes_per_batch() self._cur = 0 # current image # this class does some simple data-manipulations self.img_augment = SimpleAugment(mean=self.img_mean, shape=params['shape'], scale=params['scale'], rot=params['rot']) if 'verbose' not in params: print "BatchLoader initialized with {} sketches, {} images of {} classes".format( len(self.skt_labels), len(self.img_labels), self.num_classes) print('Hard selection: {}'.format(self.hard_sel)) #create threadpools for parallel augmentation self.pool = ThreadPool() #4
def __init__(self, params): self.batch_size = params['batch_size'] self.outshape = params['shape'] self.classes_per_batch = params['classes_per_batch'] self.img_lmdb = lmdbs(params['img_source']) if params['skt_source'].endswith('.pkl'): self.skt_lmdb = svgs(params['skt_source']) else: self.skt_lmdb = lmdbs(params['skt_source']) self.img_labels = self.img_lmdb.get_label_list() self.skt_labels = self.skt_lmdb.get_label_list() self.img_mean = biproto2py(params['mean_file']).squeeze() self.num_classes = len(set(self.skt_labels)) assert len(self.skt_labels)%self.num_classes==0, \ 'Unequal sketch training samples for each class' self.skt_per_class = len(self.skt_labels) / self.num_classes self.hard_sel = 0 self.img_labels_dict, self.classes = vec2dic(self.img_labels) self.indexlist = range(len(self.skt_labels)) self.shuffle_keeping_min_classes_per_batch() self._cur = 0 # current image # this class does some simple data-manipulations self.img_augment = SimpleAugment(mean=self.img_mean, shape=params['shape'], scale=params['scale'], rot=params['rot']) if 'verbose' not in params: print "BatchLoader initialized with {} sketches, {} images of {} classes".format( len(self.skt_labels), len(self.img_labels), self.num_classes) #create threadpools for parallel augmentation self.pool = ThreadPool() #4
def __init__(self, params): self.batch_size = params['batch_size'] self.img_shape = params['shape'] self.classes_per_batch = params['classes_per_batch'] self.img_lmdb = lmdbs(params['img_source']) if params['skt_source'].endswith('.pkl'): self.skt_lmdb = svgs(params['skt_source']) else: self.skt_lmdb = lmdbs(params['skt_source']) self.img_labels = self.img_lmdb.get_label_list() self.skt_labels = self.skt_lmdb.get_label_list() label_ids = list(set(self.img_labels)) NCATS = len(label_ids) if label_ids[0] != 0 or label_ids[-1] != NCATS - 1: if 'verbose' not in params: print 'Your data labels are not [0:{}]. Converting label ...'.format( NCATS - 1) self.img_labels = [ label_ids.index(label) for label in self.img_labels ] self.skt_labels = [ label_ids.index(label) for label in self.skt_labels ] self.img_mean = biproto2py(params['mean_file']).squeeze() #self.skt_mean = biproto2py(params['skt_mean']).squeeze() self.num_classes = len(set(self.skt_labels)) assert self.num_classes == NCATS, 'XX!!Sketch & image datasets unequal #categories' assert len(self.skt_labels)%self.num_classes==0, \ 'Unequal sketch training samples for each class' self.skt_per_class = len(self.skt_labels) / self.num_classes if 'hard_pos' in params: self.hard_sel = 1 self.hard_pos = np.load(params['hard_pos'])['pos'] elif 'hard_neg' in params: self.hard_sel = 2 self.hard_neg = np.load(params['hard_neg'])['neg'] elif 'hard_pn' in params: self.hard_sel = 3 tmp = np.load(params['hard_pn']) self.hard_pos = tmp['pos'] self.hard_neg = tmp['neg'] else: #hard selection turn off self.hard_sel = 0 #self.img_labels_dict, self.classes = vec2dic(self.img_labels) self.indexlist = range(len(self.skt_labels)) self.indexlist_img = range(len(self.img_labels)) #self.shuffle_keeping_min_classes_per_batch() shuffle(self.indexlist) shuffle(self.indexlist_img) self._cur = 0 # current image self._cur_img = 0 # this class does some simple data-manipulations self.img_augment = SimpleAugment(mean=self.img_mean, shape=self.img_shape, scale=params['scale'], rot=params['rot']) print "BatchLoader initialized with {} sketches, {} images of {} classes".format( len(self.skt_labels), len(self.img_labels), self.num_classes) #create threadpools for parallel augmentation self.pool = ThreadPool() #4