Discussion:
Help in using FANN
sumit
2007-03-19 10:19:00 UTC
Permalink
Hi
I am making a simple OCR using FANN.
I read that instead of feeding 0,1 in neural network for binary image use
-1,1 ....... I did so .
I am attaching my code below


#include <stdio.h>

#include "fann.h"

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)
{
printf("Epochs %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs,
fann_get_MSE(ann), desired_error);
return 0;
}

int main()
{
fann_type *calc_out;
const unsigned int num_input = 625; /./25*25
const unsigned int num_output = 33; //7+26
const unsigned int num_layers = 2;
const unsigned int num_neurons_hidden = 80;
const float desired_error = (const float) 0;
const unsigned int max_epochs = 1000;
const unsigned int epochs_between_reports = 10;
struct fann *ann;
struct fann_train_data *data;


printf("Creating network.\n");
ann = fann_create_standard(num_layers, num_input, num_neurons_hidden,
num_output);

data = fann_read_train_from_file("captcha.data");

fann_set_activation_steepness_hidden(ann, 1);
fann_set_activation_steepness_output(ann, 1);

fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
fann_set_bit_fail_limit(ann, 0.01f);

fann_init_weights(ann, data);

printf("Training network.\n");
fann_train_on_data(ann, data, max_epochs, epochs_between_reports,
desired_error);

printf("Testing network. %f\n", fann_test_data(ann, data));

for(int i = 0; i < fann_length_train_data(data); i++)
{
calc_out = fann_run(ann, data->input[i]);
printf("XOR test (%f,%f) -> %f, should be %f, difference=%f\n",
data->input[i][0], data->input[i][1], calc_out[0],
data->output[i][0],
fann_abs(calc_out[0] - data->output[i][0]));
}

printf("Saving network.\n");

fann_save(ann, "captcha.net");

printf("Cleaning up.\n");
fann_destroy_train(data);
fann_destroy(ann);

return 0;
}

I am getting very bad result in recognition .

How to get better result in recognition ??????
Plz provide suggestion regarding no. of hidden layers and and neurons in
hidden layers too.
How to add more than one hidden layers ?????

Thanks
--
Sumit
Steffen Nissen
2007-03-19 10:55:23 UTC
Permalink
Try training with the cascade algorithm (see
http://leenissen.dk/fann/html/files/fann_cascade-h.html), since it builds
the network for you, you do not need to set any hidden layers.

You just need to do something like this.

ann = fann_create_shortcut(2, num_input, num_output);
fann_set_activation_function_output(ann, FANN_LINEAR);
fann_set_train_error_function(ann, FANN_ERRORFUNC_LINEAR);
fann_cascadetrain_on_data(ann, train_data, max_neurons,
neurons_between_reports, desired_error);


Best of luck
Post by sumit
Hi
I am making a simple OCR using FANN.
I read that instead of feeding 0,1 in neural network for binary image use
-1,1 ....... I did so .
I am attaching my code below
#include <stdio.h>
#include " fann.h"
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)
{
printf("Epochs %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs,
fann_get_MSE(ann), desired_error);
return 0;
}
int main()
{
fann_type *calc_out;
const unsigned int num_input = 625; /./25*25
const unsigned int num_output = 33; //7+26
const unsigned int num_layers = 2;
const unsigned int num_neurons_hidden = 80;
const float desired_error = (const float) 0;
const unsigned int max_epochs = 1000;
const unsigned int epochs_between_reports = 10;
struct fann *ann;
struct fann_train_data *data;
printf("Creating network.\n");
ann = fann_create_standard(num_layers, num_input, num_neurons_hidden,
num_output);
data = fann_read_train_from_file("captcha.data");
fann_set_activation_steepness_hidden(ann, 1);
fann_set_activation_steepness_output(ann, 1);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
fann_set_bit_fail_limit(ann, 0.01f);
fann_init_weights(ann, data);
printf("Training network.\n");
fann_train_on_data(ann, data, max_epochs, epochs_between_reports,
desired_error);
printf("Testing network. %f\n", fann_test_data(ann, data));
for(int i = 0; i < fann_length_train_data(data); i++)
{
calc_out = fann_run(ann, data->input[i]);
printf("XOR test (%f,%f) -> %f, should be %f, difference=%f\n",
data->input[i][0], data->input[i][1], calc_out[0],
data->output[i][0],
fann_abs(calc_out[0] - data->output[i][0]));
}
printf("Saving network.\n");
fann_save(ann, "captcha.net");
printf("Cleaning up.\n");
fann_destroy_train(data);
fann_destroy(ann);
return 0;
}
I am getting very bad result in recognition .
How to get better result in recognition ??????
Plz provide suggestion regarding no. of hidden layers and and neurons in
hidden layers too.
How to add more than one hidden layers ?????
Thanks
--
Sumit
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Fann-general mailing list
https://lists.sourceforge.net/lists/listinfo/fann-general
--
Steffen Nissen - http://MySpace.com/SteffenNissen
Project Administrator - Fast Artificial Neural Network Library (fann)
http://fann.sf.net
Adrian Spilca
2007-03-19 11:04:26 UTC
Permalink
Post by sumit
Hi
I am making a simple OCR using FANN.
I read that instead of feeding 0,1 in neural network for binary image
use -1,1 ....... I did so. I am attaching my code below
[snip code]
Post by sumit
I am getting very bad result in recognition .
How to get better result in recognition ??????
Could be many reasons really...
It would help if you told us how the training performed. Since your
desired_error is 0, I expect that the training stopped after max_epochs
= 1000, which might not be enough.

A few suggestions:
I'm not sure what the default training algorithm is (seems like you
couldn't be bothered to choose one), but from my experience a too high
learning_rate (again, don't know what the default is) might cause
problems with certain algorithms. Also, from my experince,
fann_init_weights can initialise bad weights depending on particular
input data, you might want to try first a simple random wight init
(fann_randomise_weights?).
Post by sumit
Plz provide suggestion regarding no. of hidden layers and and neurons
in hidden layers too.How to add more than one hidden layers ?????
Not bad how you started with. I don't think you need another hidden
layer (if you still want to try, just increase num_layers and provide
the number of units for the second layer).

Hope this helps,
Adrian

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Loading...