Display training digits in UI while training
This commit is contained in:
parent
f9be5ca717
commit
5778afa121
6 changed files with 57 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "trainingdataloader.h"
|
#include "trainingdataloader.h"
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
void NetLearner::run()
|
void NetLearner::run()
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,17 @@ void NetLearner::run()
|
||||||
{
|
{
|
||||||
const TrainingDataLoader::Sample &trainingSample = dataLoader.getRandomSample();
|
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
|
||||||
|
|
|
@ -14,6 +14,7 @@ signals:
|
||||||
void logMessage(const QString &logMessage);
|
void logMessage(const QString &logMessage);
|
||||||
void progress(double progress);
|
void progress(double progress);
|
||||||
void currentNetError(double error);
|
void currentNetError(double error);
|
||||||
|
void sampleImageLoaded(const QImage &image);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETLEARNER_H
|
#endif // NETLEARNER_H
|
||||||
|
|
|
@ -31,6 +31,8 @@ void NeuroUI::on_runButton_clicked()
|
||||||
connect(m_netLearner.get(), &NetLearner::finished, this, &NeuroUI::netLearnerFinished);
|
connect(m_netLearner.get(), &NetLearner::finished, this, &NeuroUI::netLearnerFinished);
|
||||||
|
|
||||||
connect(m_netLearner.get(), &NetLearner::currentNetError, ui->errorPlotter, &ErrorPlotter::addErrorValue);
|
connect(m_netLearner.get(), &NetLearner::currentNetError, ui->errorPlotter, &ErrorPlotter::addErrorValue);
|
||||||
|
|
||||||
|
connect(m_netLearner.get(), &NetLearner::sampleImageLoaded, this, &NeuroUI::setImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_netLearner->start();
|
m_netLearner->start();
|
||||||
|
@ -61,3 +63,10 @@ void NeuroUI::progress(double progress)
|
||||||
|
|
||||||
ui->progressBar->setValue(value);
|
ui->progressBar->setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NeuroUI::setImage(const QImage &image)
|
||||||
|
{
|
||||||
|
QPixmap pixmap;
|
||||||
|
pixmap.convertFromImage(image);
|
||||||
|
ui->label->setPixmap(pixmap);
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ private slots:
|
||||||
void netLearnerStarted();
|
void netLearnerStarted();
|
||||||
void netLearnerFinished();
|
void netLearnerFinished();
|
||||||
void progress(double progress);
|
void progress(double progress);
|
||||||
|
void setImage(const QImage &image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::NeuroUI *ui;
|
Ui::NeuroUI *ui;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralWidget">
|
<widget class="QWidget" name="centralWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="logView">
|
<widget class="QListWidget" name="logView">
|
||||||
<property name="uniformItemSizes">
|
<property name="uniformItemSizes">
|
||||||
|
@ -26,6 +28,30 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<widget class="ErrorPlotter" name="errorPlotter" native="true">
|
<widget class="ErrorPlotter" name="errorPlotter" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
|
@ -37,8 +37,9 @@ void TrainingDataLoader::addSamples(const QString &sourceFile, TrainingDataLoade
|
||||||
{
|
{
|
||||||
for (int x = 0; x < scanWindow.width(); ++x)
|
for (int x = 0; x < scanWindow.width(); ++x)
|
||||||
{
|
{
|
||||||
QRgb color = sourceImage.pixel(scanPosition.x() + x, scanPosition.y() + y);
|
QRgb pixelColor = sourceImage.pixel(scanPosition.x() + x, scanPosition.y() + y);
|
||||||
sample.second[x + y * scanWindow.height()] = qGray(color) / 255.0;
|
uint grayValue = qGray(pixelColor);
|
||||||
|
sample.second[x + y * scanWindow.height()] = grayValue / 255.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue