I have the following loop:
for (int i = 1; i <= epochs; ++i) {
for (std::vector<std::filesystem::path>::iterator it = batchFiles.begin(); it != batchFiles.end(); ++it) {
struct fann_train_data *data = fann_read_train_from_file(it->string().c_str());
fann_shuffle_train_data(data);
float error = fann_train_epoch(ann, data);
}
}
ann
is the network.
batchFiles
is a std::vector<std::filesystem::path>
.
This code iterates through all the training data files in a folder and uses it to train the ANN each time, as many times as determined by the epochs
variable.
The following line causes a memory leak:
struct fann_train_data *data = fann_read_train_from_file(it->string().c_str());
The problem is that I must constantly switch between the training files, as I don't have enough memory to load them all at once, otherwise I would have loaded the training data just once.
Why does this happen? How can I resolve this?