Display training digits in UI while training

digits
mandlm 2015-10-27 18:20:50 +01:00
parent f9be5ca717
commit 5778afa121
6 changed files with 57 additions and 7 deletions

View File

@ -3,6 +3,7 @@
#include "trainingdataloader.h"
#include <QElapsedTimer>
#include <QImage>
void NetLearner::run()
{
@ -47,6 +48,17 @@ void NetLearner::run()
{
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

View File

@ -14,6 +14,7 @@ signals:
void logMessage(const QString &logMessage);
void progress(double progress);
void currentNetError(double error);
void sampleImageLoaded(const QImage &image);
};
#endif // NETLEARNER_H

View File

@ -31,6 +31,8 @@ void NeuroUI::on_runButton_clicked()
connect(m_netLearner.get(), &NetLearner::finished, this, &NeuroUI::netLearnerFinished);
connect(m_netLearner.get(), &NetLearner::currentNetError, ui->errorPlotter, &ErrorPlotter::addErrorValue);
connect(m_netLearner.get(), &NetLearner::sampleImageLoaded, this, &NeuroUI::setImage);
}
m_netLearner->start();
@ -61,3 +63,10 @@ void NeuroUI::progress(double progress)
ui->progressBar->setValue(value);
}
void NeuroUI::setImage(const QImage &image)
{
QPixmap pixmap;
pixmap.convertFromImage(image);
ui->label->setPixmap(pixmap);
}

View File

@ -28,6 +28,7 @@ private slots:
void netLearnerStarted();
void netLearnerFinished();
void progress(double progress);
void setImage(const QImage &image);
private:
Ui::NeuroUI *ui;

View File

@ -20,11 +20,37 @@
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="logView">
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="logView">
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>128</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="ErrorPlotter" name="errorPlotter" native="true">

View File

@ -37,8 +37,9 @@ void TrainingDataLoader::addSamples(const QString &sourceFile, TrainingDataLoade
{
for (int x = 0; x < scanWindow.width(); ++x)
{
QRgb color = sourceImage.pixel(scanPosition.x() + x, scanPosition.y() + y);
sample.second[x + y * scanWindow.height()] = qGray(color) / 255.0;
QRgb pixelColor = sourceImage.pixel(scanPosition.x() + x, scanPosition.y() + y);
uint grayValue = qGray(pixelColor);
sample.second[x + y * scanWindow.height()] = grayValue / 255.0;
}
}