I'm trying to train a network to classify images, and the error rate gets stuck at 0.5. Am I doing something wrong?
#include "ffbpneuralnet.h"
int main(int argc,char **argv)
{
srand(time(0));
const size_t image_width = 64;
const size_t image_height = 64;
const size_t bytes_per_pixel = 4;
const size_t output_bits = 2;
tga_32bit_image peacock_img;
peacock_img.load("peacock.tga tga_32bit_image dove_img;
dove_img.load("dove.tga tga_32bit_image flowers_img;
flowers_img.load("flowers.tga tga_32bit_image statue_img;
statue_img.load("statue.tga
vector<size_t> HiddenLayers;
HiddenLayers.push_back(sqrt(image_width*image_height*bytes_per_pixel*output_bits));
FFBPNeuralNet NNet(image_width*image_height*bytes_per_pixel, HiddenLayers, output_bits);
double max_error_rate = 0.01;
long unsigned int max_training_sessions = 1000;
double error_rate = 0.0;
long unsigned int num_training_sessions = 0;
bool use_mse_error = false;
// train network until the error rate goes below the maximum error rate
// or we reach the maximum number of training sessions (which could be considered as "giving up")
do
{
tga_32bit_image peacock_noise_img;
tga_32bit_image dove_noise_img;
tga_32bit_image flowers_noise_img;
tga_32bit_image statue_noise_img;
double noise_scale = 0.1;
peacock_noise_img = peacock_img;
peacock_noise_img.add_colour_noise(noise_scale);
dove_noise_img = dove_img;
dove_noise_img.add_colour_noise(noise_scale);
flowers_noise_img = flowers_img;
flowers_noise_img.add_colour_noise(noise_scale);
statue_noise_img = statue_img;
statue_noise_img.add_colour_noise(noise_scale);
vector<double> data;
for(size_t i = 0; i < image_width*image_height; i++)
{
data.push_back(peacock_noise_img.pixels[i].r / 255.0);
data.push_back(peacock_noise_img.pixels[i].g / 255.0);
data.push_back(peacock_noise_img.pixels[i].b / 255.0);
data.push_back(peacock_noise_img.pixels[i].a / 255.0);
}
NNet.FeedForward(data);
data.clear();
data.push_back(0.0);
data.push_back(0.0);
error_rate = NNet.BackPropagate(data, use_mse_error);
data.clear();
for(size_t i = 0; i < image_width*image_height; i++)
{
data.push_back(dove_noise_img.pixels[i].r / 255.0);
data.push_back(dove_noise_img.pixels[i].g / 255.0);
data.push_back(dove_noise_img.pixels[i].b / 255.0);
data.push_back(dove_noise_img.pixels[i].a / 255.0);
}
NNet.FeedForward(data);
data.clear();
data.push_back(1.0);
data.push_back(0.0);
error_rate += NNet.BackPropagate(data, use_mse_error);
data.clear();
for(size_t i = 0; i < image_width*image_height; i++)
{
data.push_back(flowers_noise_img.pixels[i].r / 255.0);
data.push_back(flowers_noise_img.pixels[i].g / 255.0);
data.push_back(flowers_noise_img.pixels[i].b / 255.0);
data.push_back(flowers_noise_img.pixels[i].a / 255.0);
}
NNet.FeedForward(data);
data.clear();
data.push_back(0.0);
data.push_back(1.0);
error_rate += NNet.BackPropagate(data, use_mse_error);
data.clear();
for(size_t i = 0; i < image_width*image_height; i++)
{
data.push_back(statue_noise_img.pixels[i].r / 255.0);
data.push_back(statue_noise_img.pixels[i].g / 255.0);
data.push_back(statue_noise_img.pixels[i].b / 255.0);
data.push_back(statue_noise_img.pixels[i].a / 255.0);
}
NNet.FeedForward(data);
data.clear();
data.push_back(1.0);
data.push_back(1.0);
error_rate += NNet.BackPropagate(data, use_mse_error);
error_rate /= 4.0;
num_training_sessions++;
cout << num_training_sessions << " " << error_rate << endl;
}
while(error_rate >= max_error_rate && num_training_sessions < max_training_sessions);
return 0;
}
↧