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 <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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ private slots:
|
|||
void netLearnerStarted();
|
||||
void netLearnerFinished();
|
||||
void progress(double progress);
|
||||
void setImage(const QImage &image);
|
||||
|
||||
private:
|
||||
Ui::NeuroUI *ui;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="logView">
|
||||
<property name="uniformItemSizes">
|
||||
|
@ -26,6 +28,30 @@
|
|||
</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">
|
||||
<property name="sizePolicy">
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue