-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfer_yolo_v11_widget.py
132 lines (107 loc) · 4.84 KB
/
infer_yolo_v11_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
from ikomia import core, dataprocess
from ikomia.utils import pyqtutils, qtconversion
from infer_yolo_v11.infer_yolo_v11_process import InferYoloV11Param
# PyQt GUI framework
from PyQt5.QtWidgets import *
from torch.cuda import is_available
# --------------------
# - Class which implements widget associated with the algorithm
# - Inherits PyCore.CWorkflowTaskWidget from Ikomia API
# --------------------
class InferYoloV11Widget(core.CWorkflowTaskWidget):
def __init__(self, param, parent):
core.CWorkflowTaskWidget.__init__(self, parent)
if param is None:
self.parameters = InferYoloV11Param()
else:
self.parameters = param
# Create layout : QGridLayout by default
self.grid_layout = QGridLayout()
# Cuda
self.check_cuda = pyqtutils.append_check(
self.grid_layout, "Cuda", self.parameters.cuda and is_available())
self.check_cuda.setEnabled(is_available())
# Model name
self.combo_model = pyqtutils.append_combo(
self.grid_layout, "Model name")
self.combo_model.addItem("yolo11n")
self.combo_model.addItem("yolo11s")
self.combo_model.addItem("yolo11m")
self.combo_model.addItem("yolo11l")
self.combo_model.addItem("yolo11x")
self.combo_model.setCurrentText(self.parameters.model_name)
# Hyper-parameters
custom_weight = bool(self.parameters.model_weight_file)
self.check_cfg = QCheckBox("Custom model")
self.check_cfg.setChecked(custom_weight)
self.grid_layout.addWidget(
self.check_cfg, self.grid_layout.rowCount(), 0, 1, 2)
self.check_cfg.stateChanged.connect(self.on_custom_weight_changed)
self.label_hyp = QLabel("Model weight (.pt)")
self.browse_weight_file = pyqtutils.BrowseFileWidget(
path=self.parameters.model_weight_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_weight_file, row, 1)
self.label_hyp.setVisible(custom_weight)
self.browse_weight_file.setVisible(custom_weight)
# Input size
self.spin_input_size = pyqtutils.append_spin(
self.grid_layout,
"Input size",
self.parameters.input_size
)
# Confidence threshold
self.spin_conf_thres = pyqtutils.append_double_spin(
self.grid_layout,
"Confidence threshold",
self.parameters.conf_thres,
min=0.,
max=1.,
step=0.01,
decimals=2
)
# Confidence IOU
self.spin_iou_thres = pyqtutils.append_double_spin(
self.grid_layout,
"Confidence IoU",
self.parameters.iou_thres,
min=0.,
max=1.,
step=0.01,
decimals=2
)
# PyQt -> Qt wrapping
layout_ptr = qtconversion.PyQtToQt(self.grid_layout)
# Set widget layout
self.set_layout(layout_ptr)
def on_custom_weight_changed(self, int):
self.label_hyp.setVisible(self.check_cfg.isChecked())
self.browse_weight_file.setVisible(self.check_cfg.isChecked())
def on_apply(self):
# Apply button clicked slot
self.parameters.model_name = self.combo_model.currentText()
self.parameters.cuda = self.check_cuda.isChecked()
self.parameters.input_size = self.spin_input_size.value()
self.parameters.conf_thres = self.spin_conf_thres.value()
self.parameters.iou_thres = self.spin_iou_thres.value()
if self.check_cfg.isChecked():
self.parameters.model_weight_file = self.browse_weight_file.path
self.parameters.update = True
# Send signal to launch the process
self.emit_apply(self.parameters)
# --------------------
# - Factory class to build algorithm widget object
# - Inherits PyDataProcess.CWidgetFactory from Ikomia API
# --------------------
class InferYoloV11WidgetFactory(dataprocess.CWidgetFactory):
def __init__(self):
dataprocess.CWidgetFactory.__init__(self)
# Set the algorithm name attribute -> it must be the same as the one declared in the algorithm factory class
self.name = "infer_yolo_v11"
def create(self, param):
# Create widget object
return InferYoloV11Widget(param, None)