Вы всегда можете написать генератор самостоятельно.
mat_locations = [...] # list containing paths to all mat files
def mat_generator():
indices = np.random.permutation(len(mat_locations)) # shuffle the data
ind = 0
while i < len(indices):
yield scipy.io.loadmat(mat_locations[i])
i+= 1
gen = mat_generator()
Затем вы можете перебирать gen и загружать файлы матов один за другим . В зависимости от ключей, которые имеют ваши файлы матов, и формы возвращаемых массивов, вы можете объединить несколько массивов вместе и вернуть их как пакет.
mat_locations = [...]
def load_mat_files(list_of_mat_files):
'''
Loads a series of mat files from a list and returns them as a batch
'''
out = []
for file in list_of_mat_files:
mat = scipy.io.loadmat(file)
processed_mat = ... # do your magic here
out.append(processed_mat)
return np.stack(out)
def mat_generator(batch_size=128):
'''
Generator that loads
'''
indices = np.random.permutation(len(mat_locations)) # shuffle the data
ind = 0
while ind < len(indices):
yield load_mat_files(mat_locations[ind:ind+batch_size])
ind += batch_size
gen = mat_generator()
Теперь gen
может быть перебирать и возвращать пакеты данных. Вы можете тренировать свою модель так:
for e in range(epochs):
gen = mat_generator() # initialize the generator at each epoch
for x in gen:
# train model