augment.py
def batch_generator(self, simulate_labels=False):
        """
        Generator used to load images in batches as they are passed to the network, rather than loading them into
        memory all at once.
        :param simulate_labels: Set True to avoid loading images and only fill labels. Used for diagnostic purposes.
        :return: A batch of (features, labels) as numpy arrays, ready to be passed to the network.
        """
        # Create a mapping that decides the type of image to return on each call to the generator.
        FLIP_ID = -1  # request to generate a flipped image
        SIDE_ID = -2  # request to use a side camera image
        sample_map = list(range(self.n_raw_samples)) + \
                     [FLIP_ID] * self.n_flips + \
                     [SIDE_ID] * self.n_sidecam

        while True:
            sample_map = shuffle(sample_map)
            for batch_start in range(0, len(sample_map), self.batch_size):
                features_batch = []
                labels_batch = []
                for id in sample_map[batch_start:batch_start + self.batch_size]:
                    if id >= 0:
                        # id refers to a raw image
                        sample = self.raw_samples[id]
                        f_img = sample['img_center']
                        image = imread(f_img) if not simulate_labels else f_img
                        angle = sample['angle']
                    else:
                        # Augment a random sample
                        sample = self.raw_samples[random.randint(0, self.n_raw_samples - 1)]
                        if id == FLIP_ID:
                            # Augment with reflection
                            f_img = sample['img_center']
                            image = np.fliplr(imread(f_img)) if not simulate_labels else f_img
                            angle = -sample['angle']
                        elif id == SIDE_ID:
                            # Augment with one side image
                            side = random.randint(0, 1)
                            if side == 0:
                                # Augment with left camera
                                f_img = sample['img_left']
                                image = imread(f_img) if not simulate_labels else f_img
                                angle = sample['angle'] + self.sidecam_offset
                            elif side == 1:
                                # Augment with right camera
                                f_img = sample['img_right']
                                image = imread(f_img) if not simulate_labels else f_img
                                angle = sample['angle'] - self.sidecam_offset
                    features_batch.append(image)
                    labels_batch.append(angle)
                yield np.array(features_batch), np.array(labels_batch)

        Generator used to load images in batches as they are passed to the network, rather than loading them into
        memory all at once.
        :param simulate_labels: Set True to avoid loading images and only fill labels. Used for diagnostic purposes.
        :return: A batch of (features, labels) as numpy arrays, ready to be passed to the network.
        
Generator used to load images in batches as they are passed to the network, rather than loading them into
memory all at once.
Generator used to load images in batches as they are passed to the network rather than loading them into memory all at once .
def batch_generator(self, simulate_labels=False):
        FLIP_ID = -1  
        SIDE_ID = -2  
        sample_map = list(range(self.n_raw_samples)) + \
                     [FLIP_ID] * self.n_flips + \
                     [SIDE_ID] * self.n_sidecam
        while True:
            sample_map = shuffle(sample_map)
            for batch_start in range(0, len(sample_map), self.batch_size):
                features_batch = []
                labels_batch = []
                for id in sample_map[batch_start:batch_start + self.batch_size]:
                    if id >= 0:
                        sample = self.raw_samples[id]
                        f_img = sample['img_center']
                        image = imread(f_img) if not simulate_labels else f_img
                        angle = sample['angle']
                    else:
                        sample = self.raw_samples[random.randint(0, self.n_raw_samples - 1)]
                        if id == FLIP_ID:
                            f_img = sample['img_center']
                            image = np.fliplr(imread(f_img)) if not simulate_labels else f_img
                            angle = -sample['angle']
                        elif id == SIDE_ID:
                            side = random.randint(0, 1)
                            if side == 0:
                                f_img = sample['img_left']
                                image = imread(f_img) if not simulate_labels else f_img
                                angle = sample['angle'] + self.sidecam_offset
                            elif side == 1:
                                f_img = sample['img_right']
                                image = imread(f_img) if not simulate_labels else f_img
                                angle = sample['angle'] - self.sidecam_offset
                    features_batch.append(image)
                    labels_batch.append(angle)
                yield np.array(features_batch), np.array(labels_batch)
def batch_generator ( self , simulate_labels = False ) : FLIP_ID = - 1 SIDE_ID = - 2 sample_map = list ( range ( self . n_raw_samples ) ) + [ FLIP_ID ] * self . n_flips + [ SIDE_ID ] * self . n_sidecam while True : sample_map = shuffle ( sample_map ) for batch_start in range ( 0 , len ( sample_map ) , self . batch_size ) : features_batch = [ ] labels_batch = [ ] for id in sample_map [ batch_start : batch_start + self . batch_size ] : if id >= 0 : sample = self . raw_samples [ id ] f_img = sample [ 'img_center' ] image = imread ( f_img ) if not simulate_labels else f_img angle = sample [ 'angle' ] else : sample = self . raw_samples [ random . randint ( 0 , self . n_raw_samples - 1 ) ] if id == FLIP_ID : f_img = sample [ 'img_center' ] image = np . fliplr ( imread ( f_img ) ) if not simulate_labels else f_img angle = - sample [ 'angle' ] elif id == SIDE_ID : side = random . randint ( 0 , 1 ) if side == 0 : f_img = sample [ 'img_left' ] image = imread ( f_img ) if not simulate_labels else f_img angle = sample [ 'angle' ] + self . sidecam_offset elif side == 1 : f_img = sample [ 'img_right' ] image = imread ( f_img ) if not simulate_labels else f_img angle = sample [ 'angle' ] - self . sidecam_offset features_batch . append ( image ) labels_batch . append ( angle ) yield np . array ( features_batch ) , np . array ( labels_batch )
Generator used to load images in batches as they are passed to the network, rather than loading them into
memory all at once.
Generator used to load images in batches as they are passed to the network rather than loading them into memory all at once .
"""
        Generator used to load images in batches as they are passed to the network, rather than loading them into
        memory all at once.
        :param simulate_labels: Set True to avoid loading images and only fill labels. Used for diagnostic purposes.
        :return: A batch of (features, labels) as numpy arrays, ready to be passed to the network.
        """ # Create a mapping that decides the type of image to return on each call to the generator.
 # request to generate a flipped image
 # request to use a side camera image
 # id refers to a raw image
 # Augment a random sample
 # Augment with reflection
 # Augment with one side image
 # Augment with left camera
 # Augment with right camera

A batch of (features, labels) as numpy arrays, ready to be passed to the network.
A batch of ( features labels ) as numpy arrays ready to be passed to the network .
self
simulate_labels
Set True to avoid loading images and only fill labels. Used for diagnostic purposes.
Set True to avoid loading images and only fill labels . Used for diagnostic purposes .