-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrain_yolo_v7_widget.py
142 lines (113 loc) · 6.28 KB
/
train_yolo_v7_widget.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright (C) 2021 Ikomia SAS
# Contact: https://www.ikomia.com
#
# This file is part of the IkomiaStudio software.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ikomia import core, dataprocess
from ikomia.utils import pyqtutils, qtconversion
from train_yolo_v7.train_yolo_v7_process import TrainYolov7Param
from train_yolo_v7.ikutils import model_zoo
# PyQt GUI framework
from PyQt5.QtWidgets import *
# --------------------
# - Class which implements widget associated with the process
# - Inherits PyCore.CWorkflowTaskWidget from Ikomia API
# --------------------
class TrainYolov7Widget(core.CWorkflowTaskWidget):
def __init__(self, param, parent):
core.CWorkflowTaskWidget.__init__(self, parent)
if param is None:
self.parameters = TrainYolov7Param()
else:
self.parameters = param
# Create layout : QGridLayout by default
self.grid_layout = QGridLayout()
# Dataset folder
self.browse_dataset_folder = pyqtutils.append_browse_file(self.grid_layout, label="Dataset folder",
path=self.parameters.cfg["dataset_folder"],
tooltip="Select folder",
mode=QFileDialog.Directory)
# Model name
self.combo_model_name = pyqtutils.append_combo(self.grid_layout, "Model name")
for model_name in model_zoo.keys():
self.combo_model_name.addItem(model_name)
self.combo_model_name.setCurrentText(self.parameters.cfg["model_name"])
# Epochs
self.spin_epochs = pyqtutils.append_spin(self.grid_layout, "Epochs", self.parameters.cfg["epochs"])
# Batch size
self.spin_batch = pyqtutils.append_spin(self.grid_layout, "Batch size", self.parameters.cfg["batch_size"])
# Input size
self.spin_train_imgsz = pyqtutils.append_spin(self.grid_layout, "Train image size",
self.parameters.cfg["train_imgsz"])
self.spin_test_imgsz = pyqtutils.append_spin(self.grid_layout, "Test image size",
self.parameters.cfg["test_imgsz"])
# Hyper-parameters
custom_hyp = bool(self.parameters.cfg["config_file"])
self.check_hyp = QCheckBox("Custom hyper-parameters")
self.check_hyp.setChecked(custom_hyp)
self.grid_layout.addWidget(self.check_hyp, self.grid_layout.rowCount(), 0, 1, 2)
self.check_hyp.stateChanged.connect(self.on_custom_hyp_changed)
self.label_hyp = QLabel("Hyper-parameters file")
self.browse_hyp_file = pyqtutils.BrowseFileWidget(path=self.parameters.cfg["config_file"],
tooltip="Select file",
mode=QFileDialog.ExistingFile)
row = self.grid_layout.rowCount()
self.grid_layout.addWidget(self.label_hyp, row, 0)
self.grid_layout.addWidget(self.browse_hyp_file, row, 1)
self.label_hyp.setVisible(custom_hyp)
self.browse_hyp_file.setVisible(custom_hyp)
# Model weight file
self.browse_model_weight_file = pyqtutils.append_browse_file(self.grid_layout, label="Model weight file",
path=self.parameters.cfg["model_weight_file"],
tooltip="Select file", mode=QFileDialog.ExistingFile)
# Output folder
self.browse_out_folder = pyqtutils.append_browse_file(self.grid_layout, label="Output folder",
path=self.parameters.cfg["output_folder"],
tooltip="Select folder",
mode=QFileDialog.Directory)
# PyQt -> Qt wrapping
layout_ptr = qtconversion.PyQtToQt(self.grid_layout)
# Set widget layout
self.set_layout(layout_ptr)
def on_custom_hyp_changed(self, int):
self.label_hyp.setVisible(self.check_hyp.isChecked())
self.browse_hyp_file.setVisible(self.check_hyp.isChecked())
def on_apply(self):
# Apply button clicked slot
# Get parameters from widget
self.parameters.cfg["dataset_folder"] = self.browse_dataset_folder.path
self.parameters.cfg["model_name"] = self.combo_model_name.currentText()
self.parameters.cfg["epochs"] = self.spin_epochs.value()
self.parameters.cfg["batch_size"] = self.spin_batch.value()
self.parameters.cfg["train_imgsz"] = self.spin_train_imgsz.value()
self.parameters.cfg["test_imgsz"] = self.spin_test_imgsz.value()
self.parameters.cfg["model_weight_file"] = self.browse_model_weight_file.path
if self.check_hyp.isChecked():
self.parameters.cfg["config_file"] = self.browse_hyp_file.path
self.parameters.cfg["output_folder"] = self.browse_out_folder.path
# Send signal to launch the process
self.emit_apply(self.parameters)
# --------------------
# - Factory class to build process widget object
# - Inherits PyDataProcess.CWidgetFactory from Ikomia API
# --------------------
class TrainYolov7WidgetFactory(dataprocess.CWidgetFactory):
def __init__(self):
dataprocess.CWidgetFactory.__init__(self)
# Set the name of the process -> it must be the same as the one declared in the process factory class
self.name = "train_yolo_v7"
def create(self, param):
# Create widget object
return TrainYolov7Widget(param, None)