Removed useless training images, added MNIST database instead
See http://yann.lecun.com/exdb/mnist/
BIN
gui/NeuroUI/MNIST Database/t10k-images.idx3-ubyte
Normal file
BIN
gui/NeuroUI/MNIST Database/t10k-labels.idx1-ubyte
Normal file
BIN
gui/NeuroUI/MNIST Database/train-images.idx3-ubyte
Normal file
BIN
gui/NeuroUI/MNIST Database/train-labels.idx1-ubyte
Normal file
@ -19,7 +19,7 @@ SOURCES += main.cpp\
|
|||||||
../../Neuron.cpp \
|
../../Neuron.cpp \
|
||||||
netlearner.cpp \
|
netlearner.cpp \
|
||||||
errorplotter.cpp \
|
errorplotter.cpp \
|
||||||
trainingdataloader.cpp
|
mnistloader.cpp
|
||||||
|
|
||||||
HEADERS += neuroui.h \
|
HEADERS += neuroui.h \
|
||||||
../../Layer.h \
|
../../Layer.h \
|
||||||
@ -27,7 +27,7 @@ HEADERS += neuroui.h \
|
|||||||
../../Neuron.h \
|
../../Neuron.h \
|
||||||
netlearner.h \
|
netlearner.h \
|
||||||
errorplotter.h \
|
errorplotter.h \
|
||||||
trainingdataloader.h
|
mnistloader.h
|
||||||
|
|
||||||
FORMS += neuroui.ui
|
FORMS += neuroui.ui
|
||||||
|
|
||||||
|
12
gui/NeuroUI/mnistloader.cpp
Normal 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
@ -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
|
@ -1,6 +1,6 @@
|
|||||||
#include "netlearner.h"
|
#include "netlearner.h"
|
||||||
#include "../../Net.h"
|
#include "../../Net.h"
|
||||||
#include "trainingdataloader.h"
|
#include "mnistloader.h"
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
@ -14,27 +14,9 @@ void NetLearner::run()
|
|||||||
emit logMessage("Loading training data...");
|
emit logMessage("Loading training data...");
|
||||||
emit progress(0.0);
|
emit progress(0.0);
|
||||||
|
|
||||||
TrainingDataLoader dataLoader;
|
MnistLoader mnistLoader;
|
||||||
dataLoader.addSamples("../NeuroUI/training data/mnist_train0.jpg", 0);
|
mnistLoader.load("../NeuroUI/MNIST Aatabase/train-images.idx3-ubyte",
|
||||||
emit progress(0.1);
|
"../NeuroUI/MNIST Aatabase/train-labels.idx1-ubyte");
|
||||||
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);
|
|
||||||
|
|
||||||
emit logMessage("done");
|
emit logMessage("done");
|
||||||
emit progress(0.0);
|
emit progress(0.0);
|
||||||
@ -46,25 +28,12 @@ void NetLearner::run()
|
|||||||
size_t numIterations = 10000;
|
size_t numIterations = 10000;
|
||||||
for (size_t iteration = 0; iteration < numIterations; ++iteration)
|
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 =
|
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();
|
std::vector<double> outputValues = digitClassifier.getOutput();
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 245 KiB |
Before Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 246 KiB |
Before Width: | Height: | Size: 236 KiB |
Before Width: | Height: | Size: 214 KiB |
Before Width: | Height: | Size: 206 KiB |
Before Width: | Height: | Size: 218 KiB |
Before Width: | Height: | Size: 212 KiB |
Before Width: | Height: | Size: 230 KiB |
Before Width: | Height: | Size: 214 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 932 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 1.2 MiB |
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|