'Applying a flip function to image data generator causes memory error

I've been looking at this tutorial for implementing time test augmentation to my model. Since I'm using image generators I tried doing something like this:

 tta_datagen = ImageDataGenerator()
 tta_generator = tta_datagen.flow_from_dataframe(
    dataframe = X_test_bal,
    x_col = 'uuid',
    y_col = 'group',
    target_size = (260, 260),
    directory = DATA_FOLDERS_PATH,
    class_mode = 'categorical',
    batch_size = 10,
    shuffle = False
)

def flip_lr(images):
    return np.flip(images, axis = 2)

def shift(images, shift, axis):
    return np.roll(images, shift, axis = axis)

def rotate(images, angle):
    return sp.ndimage.rotate(images, angle, axes(1, 2), reshape = False, mode='nearest')

y_pred_f = train_model.predict(flip_lr(tta_generator))

This always causes ram memory error (I'm running this on kaggle with 13GB ram). Is there a way to reduce the memory or am I doing something wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source