train.py
def generator(samples, batch_size=32):
    """Takes the a list of filenames and generates a list of images
    """
    n_samples = len(samples)
    while True: # Loop forever so the generator never exits, as expected by keras.fit_generator
        for offset in range(0, n_samples, batch_size):
            batch_filenames = samples[offset:offset+batch_size]
            images = []
            labels = []
            for filename in batch_filenames:
                filename = str(filename)
                if 'non' in filename: # It's a nonvehicle image
                    label = 0
                else:
                    label = 1
                image = cv2.imread(filename)
                if image is None:
                    print('Error! Cannot find image')
                    pdb.set_trace()
                image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Fixes cv2.imread
                images.append(image)
                labels.append(label)

            # After we've run through the entire batch, go through and augment the data via mirroring
            aug_images = []
            aug_labels = []
            for image, label in zip(images, labels):
                flipped_image = cv2.flip(image, 1)
                aug_images.append(flipped_image)
                aug_labels.append(label)
            images += aug_images
            labels += aug_labels

            X_train = np.array(images)
            y_train = np.array(labels)
            yield sklearn.utils.shuffle(X_train, y_train)
Takes the a list of filenames and generates a list of images
    
Takes the a list of filenames and generates a list of images
Takes the a list of filenames and generates a list of images
def generator(samples, batch_size=32):
    n_samples = len(samples)
    while True: 
        for offset in range(0, n_samples, batch_size):
            batch_filenames = samples[offset:offset+batch_size]
            images = []
            labels = []
            for filename in batch_filenames:
                filename = str(filename)
                if 'non' in filename: 
                    label = 0
                else:
                    label = 1
                image = cv2.imread(filename)
                if image is None:
                    print('Error! Cannot find image')
                    pdb.set_trace()
                image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) 
                images.append(image)
                labels.append(label)
            aug_images = []
            aug_labels = []
            for image, label in zip(images, labels):
                flipped_image = cv2.flip(image, 1)
                aug_images.append(flipped_image)
                aug_labels.append(label)
            images += aug_images
            labels += aug_labels
            X_train = np.array(images)
            y_train = np.array(labels)
            yield sklearn.utils.shuffle(X_train, y_train)
def generator ( samples , batch_size = 32 ) : n_samples = len ( samples ) while True : for offset in range ( 0 , n_samples , batch_size ) : batch_filenames = samples [ offset : offset + batch_size ] images = [ ] labels = [ ] for filename in batch_filenames : filename = str ( filename ) if 'non' in filename : label = 0 else : label = 1 image = cv2 . imread ( filename ) if image is None : print ( 'Error! Cannot find image' ) pdb . set_trace ( ) image = cv2 . cvtColor ( image , cv2 . COLOR_BGR2RGB ) images . append ( image ) labels . append ( label ) aug_images = [ ] aug_labels = [ ] for image , label in zip ( images , labels ) : flipped_image = cv2 . flip ( image , 1 ) aug_images . append ( flipped_image ) aug_labels . append ( label ) images += aug_images labels += aug_labels X_train = np . array ( images ) y_train = np . array ( labels ) yield sklearn . utils . shuffle ( X_train , y_train )
Takes the a list of filenames and generates a list of images
Takes the a list of filenames and generates a list of images
"""Takes the a list of filenames and generates a list of images
    """ # Loop forever so the generator never exits, as expected by keras.fit_generator # It's a nonvehicle image # Fixes cv2.imread # After we've run through the entire batch, go through and augment the data via mirroring
samples
batch_size