Skip to content

Instantly share code, notes, and snippets.

View EdsonAvelar's full-sized avatar
🎯
Focusing

Adriano Avelar EdsonAvelar

🎯
Focusing
View GitHub Profile
@arnaldog12
arnaldog12 / BalancedDataGenerator.py
Last active July 9, 2022 03:32
BalancedDataGenerator
from keras.utils.data_utils import Sequence
from imblearn.over_sampling import RandomOverSampler
from imblearn.keras import balanced_batch_generator
class BalancedDataGenerator(Sequence):
"""ImageDataGenerator + RandomOversampling"""
def __init__(self, x, y, datagen, batch_size=32):
self.datagen = datagen
self.batch_size = min(batch_size, x.shape[0])
datagen.fit(x)