-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
128 lines (117 loc) · 4.48 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "optiontablewidget.hpp"
#include <QFileDialog>
#include <QSettings>
#include <QMovie>
#include <QMessageBox>
#include "console.h"
#include "TIPL/tipl.hpp"
#include <QSettings>
QSettings settings("settings.ini",QSettings::IniFormat);
extern std::vector<std::string> gpu_names;
void gen_list(std::vector<std::string>& network_list);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->option_widget_layout->addWidget(option = new OptionTableWidget(*this,ui->option_widget,":/options.txt"));
ui->postproc_widget_layout->addWidget(eval_option = new OptionTableWidget(*this,ui->postproc_widget,":/postproc.txt"));
connect(eval_option,SIGNAL(run_action(QString)),this,SLOT(run_action(QString)));
ui->postproc_widget->hide();
ui->option_widget->hide();
ui->tabWidget->setCurrentIndex(0);
ui->training_gif->setMovie(new QMovie(":/icons/icons/processing.gif"));
ui->evaluate_gif->setMovie(new QMovie(":/icons/icons/processing.gif"));
ui->eval_label_slider->setVisible(false);
ui->view1->setScene(&train_scene1);
ui->view2->setScene(&train_scene2);
ui->eval_view1->setScene(&eval_scene1);
ui->eval_view2->setScene(&eval_scene2);
ui->error_view->setScene(&error_scene);
v2c1.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
v2c1.set_range(0.0f,1.0f);
v2c2.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
v2c2.set_range(0.0f,1.0f);
eval_v2c1.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
eval_v2c1.set_range(0.0f,1.0f);
eval_v2c2.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
eval_v2c2.set_range(0.0f,1.0f);
ui->eval_contrast->hide();
// populate device list
{
QStringList device_list;
device_list << "CPU";
torch::set_num_threads(std::thread::hardware_concurrency());
if constexpr (tipl::use_cuda)
{
if (torch::cuda::is_available())
{
for(int i = 0;i < gpu_names.size();++i)
device_list << gpu_names[i].c_str();
}
}
ui->train_device->addItems(device_list);
ui->evaluate_device->addItems(device_list);
ui->train_device->setCurrentIndex(device_list.size() > 1 ? 1:0);
ui->evaluate_device->setCurrentIndex(ui->evaluate_device->count()-1);
}
// populate networks
{
ui->evaluate_builtin_networks->addItem("select or open...");
QDir dir(QCoreApplication::applicationDirPath() + "/network");
dir.setNameFilters(QStringList() << "*.net.gz");
QFileInfoList files = dir.entryInfoList(QDir::Files);
for (const QFileInfo& fileInfo : files)
ui->evaluate_builtin_networks->addItem(fileInfo.fileName().remove(".net.gz"));
ui->evaluate_builtin_networks->setCurrentText(settings.value("eval_network").toString());
}
timer = new QTimer(this);
timer->setInterval(100);
connect(timer, SIGNAL(timeout()), this, SLOT(training()));
eval_timer = new QTimer(this);
eval_timer->setInterval(1500);
connect(eval_timer, SIGNAL(timeout()), this, SLOT(evaluating()));
qApp->installEventFilter(this);
}
MainWindow::~MainWindow()
{
settings.setValue("eval_network",ui->evaluate_builtin_networks->currentText());
qApp->removeEventFilter(this);
delete ui;
}
extern console_stream console;
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
console.show_output();
return false;
}
void MainWindow::on_eval_view_dim_currentIndexChanged(int index)
{
auto currentRow = ui->evaluate_list->currentRow();
if(currentRow >= 0 && currentRow < eval_I1_buffer.size() && !eval_I1_buffer[currentRow].empty())
{
ui->eval_pos->setMaximum(eval_I1_buffer[currentRow].shape()[index]-1);
ui->eval_pos->setValue(ui->eval_pos->maximum()/2);
}
}
void MainWindow::on_view_dim_currentIndexChanged(int index)
{
ui->pos->setMaximum(I1.shape()[index]-1);
ui->pos->setValue(ui->pos->maximum()/2);
}
void MainWindow::on_label_slider_valueChanged(int value)
{
on_pos_valueChanged(ui->pos->value());
}
void MainWindow::on_eval_label_slider_valueChanged(int value)
{
on_eval_pos_valueChanged(ui->eval_pos->value());
}
void MainWindow::on_error_x_size_valueChanged(int arg1){plot_error();}
void MainWindow::on_error_y_size_valueChanged(int arg1){plot_error();}
void MainWindow::on_actionConsole_triggered()
{
static auto* con = new Console(this);
con->showNormal();
}