Milan Stejic
2007-05-07 16:17:55 UTC
I am trying to implement early stopping during cascade training (using
fann_cascadetrain_on_data). I have written a callback to do this. The
callback code I am using follows:
int FANN_API test_callback(struct fann *ann,
struct fann_train_data *train,
unsigned int max_epochs, unsigned int epochs_between_reports,
float desired_error, unsigned int epochs)
{
float test_err = fann_test_data(ann, test_data);
printf("Epochs %8d. MSE: %.5f. Desired-MSE: %.5f",
epochs, fann_get_MSE(ann), desired_error);
printf(" Train error: %.5f, Test error: %.5f",
fann_test_data(ann, train_data), test_err);
if (test_err < low_test_err)
{
low_test_err = test_err;
printf(" Saving network.\n");
fann_save(ann, "milan.net");
return 0;
}
else
{
printf("\n");
return -1;
}
}
The variables train_data, test_data, and low_test_err are program
globals. I know that's a little ugly, but I wanted to perform a quick
proof of concept before cleaning everything up.
This method of of early stopping saves the network every time the test
error is lower than the previous training iteration. Training stops
when the test error goes up from the previous iteration and the network
is not saved.
This callback appears to work fine during training and produces no
errors. The problem occurs when the saved network is loaded during
testing when a segmentation fault occurs.
I looked at fann_cascade.c to see what else is done during training and
saw:
fann_install_candidate(ann);
fann_set_shortcut_connections(ann);
Adding either of these to the callback prior to saving the network in
the callback produces a segmentation fault. What am I doing wrong?
Regards,
Milan Stejic
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
fann_cascadetrain_on_data). I have written a callback to do this. The
callback code I am using follows:
int FANN_API test_callback(struct fann *ann,
struct fann_train_data *train,
unsigned int max_epochs, unsigned int epochs_between_reports,
float desired_error, unsigned int epochs)
{
float test_err = fann_test_data(ann, test_data);
printf("Epochs %8d. MSE: %.5f. Desired-MSE: %.5f",
epochs, fann_get_MSE(ann), desired_error);
printf(" Train error: %.5f, Test error: %.5f",
fann_test_data(ann, train_data), test_err);
if (test_err < low_test_err)
{
low_test_err = test_err;
printf(" Saving network.\n");
fann_save(ann, "milan.net");
return 0;
}
else
{
printf("\n");
return -1;
}
}
The variables train_data, test_data, and low_test_err are program
globals. I know that's a little ugly, but I wanted to perform a quick
proof of concept before cleaning everything up.
This method of of early stopping saves the network every time the test
error is lower than the previous training iteration. Training stops
when the test error goes up from the previous iteration and the network
is not saved.
This callback appears to work fine during training and produces no
errors. The problem occurs when the saved network is loaded during
testing when a segmentation fault occurs.
I looked at fann_cascade.c to see what else is done during training and
saw:
fann_install_candidate(ann);
fann_set_shortcut_connections(ann);
Adding either of these to the callback prior to saving the network in
the callback produces a segmentation fault. What am I doing wrong?
Regards,
Milan Stejic
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/