Removed useless training images, added MNIST database instead

See http://yann.lecun.com/exdb/mnist/
This commit is contained in:
mandlm 2015-10-29 13:06:30 +01:00
parent 5778afa121
commit 83b4562a29
30 changed files with 34 additions and 133 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -19,7 +19,7 @@ SOURCES += main.cpp\
../../Neuron.cpp \
netlearner.cpp \
errorplotter.cpp \
trainingdataloader.cpp
mnistloader.cpp
HEADERS += neuroui.h \
../../Layer.h \
@ -27,7 +27,7 @@ HEADERS += neuroui.h \
../../Neuron.h \
netlearner.h \
errorplotter.h \
trainingdataloader.h
mnistloader.h
FORMS += neuroui.ui

View File

@ -0,0 +1,12 @@
#include "mnistloader.h"
MnistLoader::MnistLoader()
{
}
void MnistLoader::load(const std::string &databaseFileName, const std::string &labelsFileName)
{
}

14
gui/NeuroUI/mnistloader.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef MNISTLOADER_H
#define MNISTLOADER_H
#include <string>
class MnistLoader
{
public:
MnistLoader();
void load(const std::string &databaseFileName, const std::string &labelsFileName);
};
#endif // MNISTLOADER_H

View File

@ -1,6 +1,6 @@
#include "netlearner.h"
#include "../../Net.h"
#include "trainingdataloader.h"
#include "mnistloader.h"
#include <QElapsedTimer>
#include <QImage>
@ -14,27 +14,9 @@ void NetLearner::run()
emit logMessage("Loading training data...");
emit progress(0.0);
TrainingDataLoader dataLoader;
dataLoader.addSamples("../NeuroUI/training data/mnist_train0.jpg", 0);
emit progress(0.1);
dataLoader.addSamples("../NeuroUI/training data/mnist_train1.jpg", 1);
emit progress(0.2);
dataLoader.addSamples("../NeuroUI/training data/mnist_train2.jpg", 2);
emit progress(0.3);
dataLoader.addSamples("../NeuroUI/training data/mnist_train3.jpg", 3);
emit progress(0.4);
dataLoader.addSamples("../NeuroUI/training data/mnist_train4.jpg", 4);
emit progress(0.5);
dataLoader.addSamples("../NeuroUI/training data/mnist_train5.jpg", 5);
emit progress(0.6);
dataLoader.addSamples("../NeuroUI/training data/mnist_train6.jpg", 6);
emit progress(0.7);
dataLoader.addSamples("../NeuroUI/training data/mnist_train7.jpg", 7);
emit progress(0.8);
dataLoader.addSamples("../NeuroUI/training data/mnist_train8.jpg", 8);
emit progress(0.9);
dataLoader.addSamples("../NeuroUI/training data/mnist_train9.jpg", 9);
emit progress(1.0);
MnistLoader mnistLoader;
mnistLoader.load("../NeuroUI/MNIST Aatabase/train-images.idx3-ubyte",
"../NeuroUI/MNIST Aatabase/train-labels.idx1-ubyte");
emit logMessage("done");
emit progress(0.0);
@ -46,25 +28,12 @@ void NetLearner::run()
size_t numIterations = 10000;
for (size_t iteration = 0; iteration < numIterations; ++iteration)
{
const TrainingDataLoader::Sample &trainingSample = dataLoader.getRandomSample();
QImage sampleImage(32, 32, QImage::Format_ARGB32);
for (unsigned int y = 0; y < 32; ++y)
{
for (unsigned int x = 0; x < 32; ++x)
{
uchar grayValue = trainingSample.second[x + y * 32] * 255;
sampleImage.setPixel(x, y, qRgb(grayValue, grayValue, grayValue));
}
}
emit sampleImageLoaded(sampleImage);
std::vector<double> targetValues =
{
trainingSample.first / 10.0
//trainingSample.first / 10.0
};
digitClassifier.feedForward(trainingSample.second);
//digitClassifier.feedForward(trainingSample.second);
std::vector<double> outputValues = digitClassifier.getOutput();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 932 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -1,66 +0,0 @@
#include "trainingdataloader.h"
#include <sstream>
#include <QImage>
#include <QColor>
TrainingDataLoader::TrainingDataLoader()
{
}
void TrainingDataLoader::addSamples(const QString &sourceFile, TrainingDataLoader::SampleId sampleId)
{
QImage sourceImage;
if (sourceImage.load(sourceFile) == false)
{
std::ostringstream errorString;
errorString << "error loading " << sourceFile.toStdString();
throw std::runtime_error(errorString.str());
}
QSize scanWindow(32, 32);
QPoint scanPosition(0, 0);
while (scanPosition.y() + scanWindow.height() < sourceImage.height())
{
scanPosition.setX(0);
while (scanPosition.x() + scanWindow.width() < sourceImage.width())
{
Sample sample;
sample.first = sampleId;
for (int y = 0; y < scanWindow.height(); ++y)
{
for (int x = 0; x < scanWindow.width(); ++x)
{
QRgb pixelColor = sourceImage.pixel(scanPosition.x() + x, scanPosition.y() + y);
uint grayValue = qGray(pixelColor);
sample.second[x + y * scanWindow.height()] = grayValue / 255.0;
}
}
m_samples.push_back(sample);
scanPosition.rx() += scanWindow.width();
}
scanPosition.ry() += scanWindow.height();
}
}
const TrainingDataLoader::Sample &TrainingDataLoader::getRandomSample() const
{
size_t sampleIndex = (std::rand() * m_samples.size()) / RAND_MAX;
auto it = m_samples.cbegin();
for (size_t index = 0; index < sampleIndex; ++index)
{
it++;
}
return *it;
}

View File

@ -1,28 +0,0 @@
#ifndef TRAININGDATALOADER_H
#define TRAININGDATALOADER_H
#include <utility>
#include <list>
#include <string>
#include <QString>
class TrainingDataLoader
{
public:
using SampleData = double[32*32];
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);
const Sample &getRandomSample() const;
};
#endif // TRAININGDATALOADER_H