I am a little bit confused how to use fit_generator in keras.
By example lets say:
- we have 10000 datapoints
- we want to run for 10 epochs
- with batch size of 512
Using fit we just:
x, y = load_data()
model.fit(x=x, y=y, batch_size=512, epochs=10)
where load_data loads all the data.
Now how to do the same with fit_generator.
Its not clear to me how it is processed when using fit_generator. If I have the following generator:
def data_generator():
for x, y in load_data_per_line():
yield x, y
In the generator above each time it yields one data point. And:
def data_generator_2():
x_output = []
y_output = []
i = 0
for x, y in load_data_per_line():
x_output[i] = x
y_output[i] = y
i = i + 1
if i == batch_size:
yield x_output, y_output
i = 0
x_output = []
y_output = []
In the above generator every time it yields batch size data points(512 in this case).
To achieve the same as fit but using fit_generator:
model.fit_generator(data_generator(), steps_per_epoch=10000 / 512, epochs=10)
or
model.fit_generator(data_generator_2(), steps_per_epoch=10000 / 512, epochs=10)
Or both are wrong(fit_generator and data_generators)? If any of them is correct, does is guaranties that all data points will be processed and also be processed sequentially?
Any insight is useful