Started loader-class for 8x8 pixel digit training data
This commit is contained in:
parent
80da55a2b8
commit
81d1f54c98
@ -54,7 +54,7 @@ void Layer::connectTo(const Layer & nextLayer)
|
|||||||
|
|
||||||
void Layer::updateInputWeights(Layer & prevLayer)
|
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)
|
for (size_t targetLayerIndex = 0; targetLayerIndex < sizeWithoutBiasNeuron(); ++targetLayerIndex)
|
||||||
{
|
{
|
||||||
|
@ -18,14 +18,16 @@ SOURCES += main.cpp\
|
|||||||
../../Net.cpp \
|
../../Net.cpp \
|
||||||
../../Neuron.cpp \
|
../../Neuron.cpp \
|
||||||
netlearner.cpp \
|
netlearner.cpp \
|
||||||
errorplotter.cpp
|
errorplotter.cpp \
|
||||||
|
trainingdataloader.cpp
|
||||||
|
|
||||||
HEADERS += neuroui.h \
|
HEADERS += neuroui.h \
|
||||||
../../Layer.h \
|
../../Layer.h \
|
||||||
../../Net.h \
|
../../Net.h \
|
||||||
../../Neuron.h \
|
../../Neuron.h \
|
||||||
netlearner.h \
|
netlearner.h \
|
||||||
errorplotter.h
|
errorplotter.h \
|
||||||
|
trainingdataloader.h
|
||||||
|
|
||||||
FORMS += neuroui.ui
|
FORMS += neuroui.ui
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "netlearner.h"
|
#include "netlearner.h"
|
||||||
#include "../../Net.h"
|
#include "../../Net.h"
|
||||||
|
#include "trainingdataloader.h"
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ void NetLearner::run()
|
|||||||
{
|
{
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
|
|
||||||
|
TrainingDataLoader dataLoader;
|
||||||
|
dataLoader.addSamples("../NeuroUI/training data/mnist_train0.jpg", 0);
|
||||||
|
|
||||||
Net myNet;
|
Net myNet;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -26,7 +30,7 @@ void NetLearner::run()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
size_t numIterations = 1000000;
|
size_t numIterations = 2000000;
|
||||||
for (size_t iteration = 0; iteration < numIterations; ++iteration)
|
for (size_t iteration = 0; iteration < numIterations; ++iteration)
|
||||||
{
|
{
|
||||||
std::vector<double> inputValues =
|
std::vector<double> inputValues =
|
||||||
|
29
gui/NeuroUI/trainingdataloader.cpp
Normal file
29
gui/NeuroUI/trainingdataloader.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
|
26
gui/NeuroUI/trainingdataloader.h
Normal file
26
gui/NeuroUI/trainingdataloader.h
Normal 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
|
Reference in New Issue
Block a user