Repository navigation
Expand file tree
/
Copy pathclassifier.py
More file actions
65 lines (56 loc) · 2.28 KB
/
Copy pathclassifier.py
File metadata and controls
65 lines (56 loc) · 2.28 KB
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
# Classifier
# Copyright (C) 2024-2026 Collabora Ltd.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
from log.global_logger import GlobalLogger
import backend
CAN_REGISTER_ELEMENT = True
try:
from base_classifier import BaseClassifier
from engine.classifier_engine import ClassifierEngine, ExportedClassifier
from engine.engine_factory import EngineFactory
from engine.support_matrix import TASK_ENGINES
except ImportError as e:
CAN_REGISTER_ELEMENT = False
GlobalLogger().warning(
f"The 'classifier_pylm' element will not be available. Error: {e}"
)
class Classifier(BaseClassifier):
"""
GStreamer element for image classification.
"""
__gstmetadata__ = (
"Classifier",
"Transform",
"Classifier",
"Aaron Boxer <aaron.boxer@collabora.com>",
)
ACCEPTS_DEVICE_FRAMES = True
def __init__(self):
super().__init__()
self.task_engine_name = self.mgr.engine_name = "pyml_classifier_engine"
EngineFactory.register(self.mgr.engine_name, ClassifierEngine)
def export_model(self, model_name):
engine = self.mgr.engine_name
if engine not in TASK_ENGINES["classifier"]:
raise ValueError(f"{engine} does not run the classifier, see pyml-engines")
return ExportedClassifier(model_name, engine)
if CAN_REGISTER_ELEMENT and backend.BACKEND == "gst":
__gstelementfactory__ = backend.register_gst_element("pyml_classifier", Classifier)
elif not CAN_REGISTER_ELEMENT:
GlobalLogger().warning(
"The 'pyml_classifier' element will not be registered because a module is missing."
)