Started loader-class for 8x8 pixel digit training data

This commit is contained in:
mandlm 2015-10-26 22:05:50 +01:00
parent 80da55a2b8
commit 81d1f54c98
5 changed files with 65 additions and 4 deletions

View file

@ -54,7 +54,7 @@ void Layer::connectTo(const Layer & nextLayer)
void Layer::updateInputWeights(Layer & prevLayer)
{
static const double trainingRate = 0.3;
static const double trainingRate = 0.2;
for (size_t targetLayerIndex = 0; targetLayerIndex < sizeWithoutBiasNeuron(); ++targetLayerIndex)
{

View file

@ -18,14 +18,16 @@ SOURCES += main.cpp\
../../Net.cpp \
../../Neuron.cpp \
netlearner.cpp \
errorplotter.cpp
errorplotter.cpp \
trainingdataloader.cpp
HEADERS += neuroui.h \
../../Layer.h \
../../Net.h \
../../Neuron.h \
netlearner.h \
errorplotter.h
errorplotter.h \
trainingdataloader.h
FORMS += neuroui.ui

View file

@ -1,5 +1,6 @@
#include "netlearner.h"
#include "../../Net.h"
#include "trainingdataloader.h"
#include <QElapsedTimer>
@ -9,6 +10,9 @@ void NetLearner::run()
{
QElapsedTimer timer;
TrainingDataLoader dataLoader;
dataLoader.addSamples("../NeuroUI/training data/mnist_train0.jpg", 0);
Net myNet;
try
{
@ -26,7 +30,7 @@ void NetLearner::run()
timer.start();
size_t numIterations = 1000000;
size_t numIterations = 2000000;
for (size_t iteration = 0; iteration < numIterations; ++iteration)
{
std::vector<double> inputValues =

View file

@ -0,0 +1,29 @@
#include "trainingdataloader.h"
#include <QImage>
#include <QColor>
TrainingDataLoader::TrainingDataLoader()
{
}
void TrainingDataLoader::addSamples(const QString &sourceFile, TrainingDataLoader::SampleId sampleId)
{
QImage sourceImage;
sourceImage.load(sourceFile);
Sample sample;
sample.first = sampleId;
for (unsigned int y = 0; y < 8; ++y)
{
for (unsigned int x = 0; x < 8; ++x)
{
sample.second[x + y * 8] = qGray(sourceImage.pixel(x, y)) / 255.0;
}
}
m_samples.push_back(sample);
}

View file

@ -0,0 +1,26 @@
#ifndef TRAININGDATALOADER_H
#define TRAININGDATALOADER_H
#include <utility>
#include <list>
#include <string>
#include <QString>
class TrainingDataLoader
{
public:
using SampleData = double[64];
using SampleId = unsigned int;
using Sample = std::pair<SampleId, SampleData>;
private:
std::list<Sample> m_samples;
public:
TrainingDataLoader();
void addSamples(const QString &sourceFile, SampleId sampleId);
};
#endif // TRAININGDATALOADER_H