def next_minibatch(self, batch_size): ''' Return the next mini-batch, we do data augmentation during constructing each mini-batch. ''' data_size = len(self.data) batch_end = min(self.batch_start + batch_size, data_size) current_batch_size = batch_end - self.batch_start if current_batch_size < 0: raise Exception('Reach the end of the training data.') inputs = np.empty(shape=(current_batch_size, 1, self.width, self.height), dtype=np.float32) targets = np.empty(shape=(current_batch_size, self.emotion_count), dtype=np.float32) for idx in range(self.batch_start, batch_end): index = self.indices[idx] distorted_image = imgu.distort_img(self.data[index][1], self.data[index][3], self.width, self.height, self.max_shift, self.max_scale, self.max_angle, self.max_skew, self.do_flip) final_image = imgu.preproc_img(distorted_image) inputs[idx - self.batch_start] = final_image targets[idx - self.batch_start, :] = self._process_target( self.data[index][2]) self.batch_start += current_batch_size return inputs, targets, current_batch_size
def next_minibatch(self, batch_size, num_data_partitions=1, partition_index=0): ''' Return the next mini-batch, we do data augmentation during constructing each mini-batch. ''' data_size = len(self.data) total_batch_size = batch_size * num_data_partitions batch_end = min(self.batch_start + total_batch_size, data_size) current_batch_size = batch_end - self.batch_start if current_batch_size < 0: raise Exception('Reach the end of the training data.') #determine individual worker batch size, usually equals batch_size except possibly for last partiton of data, #and corresponding worker_batch_start and worker_batch_end indices worker_batch_size = current_batch_size // num_data_partitions worker_batch_start = self.batch_start + worker_batch_size * partition_index if ((partition_index + 1) == num_data_partitions): worker_batch_end = batch_end worker_batch_size = worker_batch_end - worker_batch_start else: worker_batch_end = worker_batch_start + worker_batch_size inputs = np.empty(shape=(worker_batch_size, 1, self.width, self.height), dtype=np.float32) targets = np.empty(shape=(worker_batch_size, self.emotion_count), dtype=np.float32) for idx in range(worker_batch_start, worker_batch_end): index = self.indices[idx] distorted_image = imgu.distort_img(self.data[index][1], self.data[index][3], self.width, self.height, self.max_shift, self.max_scale, self.max_angle, self.max_skew, self.do_flip) final_image = imgu.preproc_img(distorted_image) inputs[idx - worker_batch_start] = final_image targets[idx - worker_batch_start, :] = self._process_target( self.data[index][2]) self.batch_start += current_batch_size return inputs, targets, worker_batch_size