forked from CVHub520/X-AnyLabeling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_manager.py
2188 lines (2075 loc) · 81.5 KB
/
model_manager.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import copy
import time
import yaml
import importlib.resources as pkg_resources
from threading import Lock
from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
from anylabeling.utils import GenericWorker
from anylabeling.views.labeling.logger import logger
from anylabeling.config import get_config, save_config
from anylabeling.configs import auto_labeling as auto_labeling_configs
from anylabeling.services.auto_labeling.types import AutoLabelingResult
class ModelManager(QObject):
"""Model manager"""
MAX_NUM_CUSTOM_MODELS = 5
CUSTOM_MODELS = [
"doclayout_yolo",
"open_vision",
"segment_anything",
"segment_anything_2",
"segment_anything_2_video",
"sam_med2d",
"sam_hq",
"yolov5",
"yolov6",
"yolov7",
"yolov8",
"yolov8_seg",
"yolox",
"yolov5_resnet",
"yolov6_face",
"rtdetr",
"yolo_nas",
"yolox_dwpose",
"clrnet",
"ppocr_v4",
"yolov5_sam",
"efficientvit_sam",
"yolov5_track",
"damo_yolo",
"yolov8_sahi",
"grounding_sam",
"grounding_sam2",
"grounding_dino",
"yolov5_obb",
"gold_yolo",
"yolov8_efficientvit_sam",
"ram",
"yolov5_seg",
"yolov5_ram",
"yolov8_pose",
"pulc_attribute",
"internimage_cls",
"edge_sam",
"yolov5_cls",
"yolov8_cls",
"yolov8_obb",
"yolov5_car_plate",
"rtmdet_pose",
"yolov9",
"yolow",
"yolov10",
"rmbg",
"depth_anything",
"depth_anything_v2",
"yolow_ram",
"rtdetrv2",
"yolov8_det_track",
"yolov8_seg_track",
"yolov8_obb_track",
"yolov8_pose_track",
"yolo11",
"yolo11_cls",
"yolo11_obb",
"yolo11_seg",
"yolo11_pose",
"yolo11_det_track",
"yolo11_seg_track",
"yolo11_obb_track",
"yolo11_pose_track",
]
model_configs_changed = pyqtSignal(list)
new_model_status = pyqtSignal(str)
model_loaded = pyqtSignal(dict)
new_auto_labeling_result = pyqtSignal(AutoLabelingResult)
auto_segmentation_model_selected = pyqtSignal()
auto_segmentation_model_unselected = pyqtSignal()
prediction_started = pyqtSignal()
prediction_finished = pyqtSignal()
request_next_files_requested = pyqtSignal()
output_modes_changed = pyqtSignal(dict, str)
def __init__(self):
super().__init__()
self.model_configs = []
self.loaded_model_config = None
self.loaded_model_config_lock = Lock()
self.model_download_worker = None
self.model_download_thread = None
self.model_execution_thread = None
self.model_execution_thread_lock = Lock()
self.load_model_configs()
def load_model_configs(self):
"""Load model configs"""
# Load list of default models
with pkg_resources.open_text(
auto_labeling_configs, "models.yaml"
) as f:
model_list = yaml.safe_load(f)
# Load list of custom models
custom_models = get_config().get("custom_models", [])
for custom_model in custom_models:
custom_model["is_custom_model"] = True
# Remove invalid/not found custom models
custom_models = [
custom_model
for custom_model in custom_models
if os.path.isfile(custom_model.get("config_file", ""))
]
config = get_config()
config["custom_models"] = custom_models
save_config(config)
model_list += custom_models
# Load model configs
model_configs = []
for model in model_list:
model_config = {}
config_file = model["config_file"]
if config_file.startswith(":/"): # Config file is in resources
config_file_name = config_file[2:]
with pkg_resources.open_text(
auto_labeling_configs, config_file_name
) as f:
model_config = yaml.safe_load(f)
model_config["config_file"] = config_file
else: # Config file is in local file system
with open(config_file, "r", encoding="utf-8") as f:
model_config = yaml.safe_load(f)
model_config["config_file"] = os.path.normpath(
os.path.abspath(config_file)
)
model_config["is_custom_model"] = model.get(
"is_custom_model", False
)
model_configs.append(model_config)
# Sort by last used
for i, model_config in enumerate(model_configs):
# Keep order for integrated models
if not model_config.get("is_custom_model", False):
model_config["last_used"] = -i
else:
model_config["last_used"] = model_config.get(
"last_used", time.time()
)
model_configs.sort(key=lambda x: x.get("last_used", 0), reverse=True)
self.model_configs = model_configs
self.model_configs_changed.emit(model_configs)
def get_model_configs(self):
"""Return model infos"""
return self.model_configs
def set_output_mode(self, mode):
"""Set output mode"""
if self.loaded_model_config and self.loaded_model_config["model"]:
self.loaded_model_config["model"].set_output_mode(mode)
@pyqtSlot()
def on_model_download_finished(self):
"""Handle model download thread finished"""
if self.loaded_model_config and self.loaded_model_config["model"]:
self.new_model_status.emit(
self.tr("Model loaded. Ready for labeling.")
)
self.model_loaded.emit(self.loaded_model_config)
self.output_modes_changed.emit(
self.loaded_model_config["model"].Meta.output_modes,
self.loaded_model_config["model"].Meta.default_output_mode,
)
else:
self.model_loaded.emit({})
def load_custom_model(self, config_file):
"""Run custom model loading in a thread"""
config_file = os.path.normpath(os.path.abspath(config_file))
if (
self.model_download_thread is not None
and self.model_download_thread.isRunning()
):
logger.info(
"Another model is being loaded. Please wait for it to finish."
)
return
# Check config file path
if not config_file or not os.path.isfile(config_file):
logger.error(
"An error occurred while loading the custom model: "
"The model path is invalid."
)
self.new_model_status.emit(
self.tr("Error in loading custom model: Invalid path.")
)
return
# Check config file content
model_config = {}
with open(config_file, "r", encoding="utf-8") as f:
model_config = yaml.safe_load(f)
model_config["config_file"] = os.path.abspath(config_file)
if not model_config:
logger.error(
"An error occurred while loading the custom model: "
"The config file is invalid."
)
self.new_model_status.emit(
self.tr("Error in loading custom model: Invalid config file.")
)
return
if (
"type" not in model_config
or "display_name" not in model_config
or "name" not in model_config
or model_config["type"] not in self.CUSTOM_MODELS
):
if "type" not in model_config:
logger.error(
"An error occurred while loading the custom model: "
"The 'type' field is missing in the model configuration file."
)
elif "display_name" not in model_config:
logger.error(
"An error occurred while loading the custom model: "
"The 'display_name' field is missing in the model configuration file."
)
elif "name" not in model_config:
logger.error(
"An error occurred while loading the custom model: "
"The 'name' field is missing in the model configuration file."
)
else:
logger.error(
"An error occurred while loading the custom model: "
"The model type {model_config['type']} is not supported."
)
self.new_model_status.emit(
self.tr(
"Error in loading custom model: Invalid config file format."
)
)
return
# Add or replace custom model
custom_models = get_config().get("custom_models", [])
matched_index = None
for i, model in enumerate(custom_models):
if os.path.normpath(model["config_file"]) == os.path.normpath(
config_file
):
matched_index = i
break
if matched_index is not None:
model_config["last_used"] = time.time()
custom_models[matched_index] = model_config
else:
if len(custom_models) >= self.MAX_NUM_CUSTOM_MODELS:
custom_models.sort(
key=lambda x: x.get("last_used", 0), reverse=True
)
custom_models.pop()
custom_models = [model_config] + custom_models
# Save config
config = get_config()
config["custom_models"] = custom_models
save_config(config)
# Reload model configs
self.load_model_configs()
# Load model
self.load_model(model_config["config_file"])
def load_model(self, config_file):
"""Run model loading in a thread"""
if (
self.model_download_thread is not None
and self.model_download_thread.isRunning()
):
logger.info(
"Another model is being loaded. Please wait for it to finish."
)
return
if not config_file:
if self.model_download_worker is not None:
try:
self.model_download_worker.finished.disconnect(
self.on_model_download_finished
)
except TypeError:
pass
self.unload_model()
self.new_model_status.emit(self.tr("No model selected."))
return
# Check and get model id
model_id = None
for i, model_config in enumerate(self.model_configs):
if model_config["config_file"] == config_file:
model_id = i
break
if model_id is None:
logger.error(
"An error occurred while loading the model: "
"The model name is invalid."
)
self.new_model_status.emit(
self.tr("Error in loading model: Invalid model name.")
)
return
self.model_download_thread = QThread()
self.new_model_status.emit(
self.tr("Loading model: {model_name}. Please wait...").format(
model_name=self.model_configs[model_id]["display_name"]
)
)
self.model_download_worker = GenericWorker(self._load_model, model_id)
self.model_download_worker.finished.connect(
self.on_model_download_finished
)
self.model_download_worker.finished.connect(
self.model_download_thread.quit
)
self.model_download_worker.moveToThread(self.model_download_thread)
self.model_download_thread.started.connect(
self.model_download_worker.run
)
self.model_download_thread.start()
def _load_model(self, model_id): # noqa: C901
"""Load and return model info"""
if self.loaded_model_config is not None:
self.loaded_model_config["model"].unload()
self.loaded_model_config = None
self.auto_segmentation_model_unselected.emit()
model_config = copy.deepcopy(self.model_configs[model_id])
if model_config["type"] == "yolov5":
from .yolov5 import YOLOv5
try:
model_config["model"] = YOLOv5(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov6":
from .yolov6 import YOLOv6
try:
model_config["model"] = YOLOv6(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov7":
from .yolov7 import YOLOv7
try:
model_config["model"] = YOLOv7(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov8_sahi":
from .yolov8_sahi import YOLOv8_SAHI
try:
model_config["model"] = YOLOv8_SAHI(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov8":
from .yolov8 import YOLOv8
try:
model_config["model"] = YOLOv8(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov9":
from .yolov9 import YOLOv9
try:
model_config["model"] = YOLOv9(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov10":
from .yolov10 import YOLOv10
try:
model_config["model"] = YOLOv10(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolo11":
from .yolo11 import YOLO11
try:
model_config["model"] = YOLO11(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolow":
from .yolow import YOLOW
try:
model_config["model"] = YOLOW(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov5_seg":
from .yolov5_seg import YOLOv5_Seg
try:
model_config["model"] = YOLOv5_Seg(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov5_ram":
from .yolov5_ram import YOLOv5_RAM
try:
model_config["model"] = YOLOv5_RAM(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolow_ram":
from .yolow_ram import YOLOW_RAM
try:
model_config["model"] = YOLOW_RAM(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov8_seg":
from .yolov8_seg import YOLOv8_Seg
try:
model_config["model"] = YOLOv8_Seg(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolo11_seg":
from .yolo11_seg import YOLO11_Seg
try:
model_config["model"] = YOLO11_Seg(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov8_obb":
from .yolov8_obb import YOLOv8_OBB
try:
model_config["model"] = YOLOv8_OBB(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolo11_obb":
from .yolo11_obb import YOLO11_OBB
try:
model_config["model"] = YOLO11_OBB(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov8_pose":
from .yolov8_pose import YOLOv8_Pose
try:
model_config["model"] = YOLOv8_Pose(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolo11_pose":
from .yolo11_pose import YOLO11_Pose
try:
model_config["model"] = YOLO11_Pose(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolox":
from .yolox import YOLOX
try:
model_config["model"] = YOLOX(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolo_nas":
from .yolo_nas import YOLO_NAS
try:
model_config["model"] = YOLO_NAS(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "damo_yolo":
from .damo_yolo import DAMO_YOLO
try:
model_config["model"] = DAMO_YOLO(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "gold_yolo":
from .gold_yolo import Gold_YOLO
try:
model_config["model"] = Gold_YOLO(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "grounding_dino":
from .grounding_dino import Grounding_DINO
try:
model_config["model"] = Grounding_DINO(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "ram":
from .ram import RAM
try:
model_config["model"] = RAM(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "internimage_cls":
from .internimage_cls import InternImage_CLS
try:
model_config["model"] = InternImage_CLS(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "pulc_attribute":
from .pulc_attribute import PULC_Attribute
try:
model_config["model"] = PULC_Attribute(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_unselected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
return
elif model_config["type"] == "yolov5_sam":
from .yolov5_sam import YOLOv5SegmentAnything
try:
model_config["model"] = YOLOv5SegmentAnything(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_selected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa
logger.error(
f"❌ Error in loading model: {model_config['type']} with error: {str(e)}"
)
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
return
# Request next files for prediction
self.request_next_files_requested.emit()
elif model_config["type"] == "yolov8_efficientvit_sam":
from .yolov8_efficientvit_sam import YOLOv8_EfficientViT_SAM
try:
model_config["model"] = YOLOv8_EfficientViT_SAM(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_selected.emit()
logger.info(
f"✅ Model loaded successfully: {model_config['type']}"
)
except Exception as e: # noqa