|
From: Herton R. K. <he...@us...> - 2005-07-03 01:09:27
|
Update of /cvsroot/kimageprocess/kimageprocess/src/plugins/fann In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1726/plugins/fann Modified Files: fann.cpp Log Message: - Reenabled fann plugin compilation. - Fixing compiling problems on fann plugin. Index: fann.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/plugins/fann/fann.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- fann.cpp 3 Jul 2005 00:31:40 -0000 1.6 +++ fann.cpp 3 Jul 2005 01:09:17 -0000 1.7 @@ -27,6 +27,7 @@ #include <ktimage.h> #include <ktpluginmanager.h> +#include <ktpatternmanager.h> K_EXPORT_COMPONENT_FACTORY( kimageprocess_fann, KGenericFactory<KTFANNPlugin>( "kimageprocess_fann" ) ) @@ -35,7 +36,6 @@ : KTClassifBackend(parent, name) { m_network = 0; - m_img = 0; m_iterations = 300000; m_hiddenLayers = 1; m_connectionRate = 1.0; @@ -60,7 +60,7 @@ //create the network unsigned int neurons[m_hiddenLayers + 2]; - neurons[0] = inputs + neurons[0] = inputs; for ( int i=1; i < m_hiddenLayers; ++i ) { neurons[i] = inputs; } @@ -72,35 +72,40 @@ fann_set_activation_function_output(m_network, m_activationFunctionOutput); struct fann_train_data fanndata; - float *out; - float error = 0.0; + float *in, *out; + in = new float[data.count() * inputs]; out = new float[data.count() * outputs]; fanndata.num_data = data.count(); fanndata.num_input = inputs; fanndata.num_output = outputs; fanndata.input = new float*[data.count()]; fanndata.output = new float*[data.count()]; - for ( int i=0; i < data.count(); ++i ) + for ( unsigned int i=0; i < data.count(); ++i ) { + fanndata.input[i] = in + i * inputs; fanndata.output[i] = out + i * outputs; - for ( int j=0; j < m_output; ++j ) + for ( int j=0; j < outputs; ++j ) { fanndata.output[i][j] = 0; } } QValueList<dataEntry>::ConstIterator end = data.constEnd(); + int c = 0; - for ( QValueList<dataEntry>::ConstIterator it = data.constBegin(), int c=0; it != end; ++it, ++c ) + for ( QValueList<dataEntry>::ConstIterator it = data.constBegin(); it != end; ++it ) { - fanndata.inputs[c] = (*it).inputs; + for ( int i=0; i < inputs; ++i ) + fanndata.input[c][i] = (*it).inputs[i]; fanndata.output[c][(*it).sampleClass-1] = 1; + c++; } fann_init_weights(m_network, &fanndata); fann_train_on_data(m_network, &fanndata, m_iterations, m_iterations / 100, m_desiredError); //clear data + delete in; delete out; delete fanndata.input; delete fanndata.output; @@ -113,23 +118,26 @@ KTImage *c_img = KTImageManager::self()->testingImage(); QImage *img = new QImage(c_img->width(), c_img->height(), 32); - float *outputs; + float input[inputs]; + float *output; QValueList<dataEntry>::ConstIterator end = data.constEnd(); - int x = 0, y = 0; + int x = 0, y = 0, i = 0; int colorStep = 255 / (outputs - 1); int level; - for ( QValueList<dataEntry>::ConstIterator it = data.constBegin(), int i=0; it != end; ++it, ++i ) + for ( QValueList<dataEntry>::ConstIterator it = data.constBegin(); it != end; ++it ) { - outputs = fann_run(m_network, (*it).inputs); + for ( int j=0; j < inputs; ++j ) + input[j] = (*it).inputs[j]; + output = fann_run(m_network, input); int maxclass = 0; - int maxvalue = outputs[0]; + float maxvalue = output[0]; for ( int j=1; j < outputs; ++j ) { - if (outputs[j] > maxvalue) + if (output[j] > maxvalue) { maxclass = j; - maxvalue = outputs[j]; + maxvalue = output[j]; } } level = maxclass * colorStep; @@ -139,6 +147,7 @@ x = 0; y++; } + i++; } //save the image @@ -148,7 +157,7 @@ { KTempFile tmpImg(QString::null, ".pgm"); tmpImg.close(); - m_img->save(tmpImg.name(), "PGM"); + img->save(tmpImg.name(), "PGM"); KIO::NetAccess::upload(tmpImg.name(), dest, 0); KIO::NetAccess::removeTempFile(tmpImg.name()); } |