Kushalguptaiitb commited on
Commit
6ea55ae
·
verified ·
1 Parent(s): 454dae8

Delete load_model.py

Browse files
Files changed (1) hide show
  1. load_model.py +0 -106
load_model.py DELETED
@@ -1,106 +0,0 @@
1
-
2
- # from ultralytics import YOLOv10
3
- # import torch
4
- # from config.set_config import set_configuration
5
-
6
- # set_config_project = set_configuration()
7
- # layout_model_weights_path = set_config_project.layout_model_weights_path
8
- # no_of_threads = set_config_project.no_of_threads
9
-
10
- # def load_model_for_process(detection_model_path=layout_model_weights_path):
11
- # """
12
- # Load model in each subprocess to avoid CUDA initialization issues
13
-
14
- # Returns:
15
- # Model loaded in appropriate device
16
- # """
17
- # # Your model loading logic
18
- # device = "cuda" if torch.cuda.is_available() else "cpu"
19
- # # print(f"Using device: {device}")
20
-
21
- # model = YOLOv10(detection_model_path).to(device)
22
- # class_names = model.names
23
- # class_names["11"] = "Table-header"
24
- # class_names["12"] = "Portfolio-Company-Table"
25
-
26
- # return model, class_names
27
-
28
- import torch
29
-
30
- from ultralytics import YOLO
31
- layout_model_weights_path = "/shared_disk/kushal/db_str_chunking/new_ws_structured_code/db_structured_chunking/structure_chunking/model_weights/yolov12_epoch60.pt"
32
-
33
-
34
- # def load_model_for_process(detection_model_path=layout_model_weights_path):
35
- # """
36
- # Load model in each subprocess to avoid CUDA initialization issues
37
-
38
- # Returns:
39
- # Model loaded in appropriate device
40
- # """
41
- # # Your model loading logic
42
- # device = "cuda" if torch.cuda.is_available() else "cpu"
43
- # # print(f"Using device: {device}")
44
-
45
- # model = YOLO(detection_model_path).to(device)
46
- # class_names = model.names
47
- # class_names["11"] = "Table-header"
48
- # class_names["12"] = "Portfolio-Company-Table"
49
- # print("YOLOV12"*10)
50
-
51
- # return model, class_names
52
-
53
-
54
- '''Below code for docling heron model'''
55
-
56
- from transformers import RTDetrV2ForObjectDetection, RTDetrImageProcessor
57
-
58
- def load_model_for_process(model_name="ds4sd/docling-layout-heron"):
59
- """
60
- Load the Docling Heron model and image processor in each subprocess to avoid CUDA initialization issues.
61
-
62
- Returns:
63
- Tuple of (model, image_processor, class_names)
64
- """
65
- device = "cuda" if torch.cuda.is_available() else "cpu"
66
- print(f"Using device: {device}")
67
-
68
- # Load the image processor and model
69
- image_processor = RTDetrImageProcessor.from_pretrained(model_name)
70
- model = RTDetrV2ForObjectDetection.from_pretrained(model_name).to(device)
71
-
72
- # Define class names mapping
73
- class_names = {
74
- 0: "Caption",
75
- 1: "Footnote",
76
- 2: "Formula",
77
- 3: "List-item",
78
- 4: "Page-footer",
79
- 5: "Page-header",
80
- 6: "Picture",
81
- 7: "Section-header",
82
- 8: "Table",
83
- 9: "Text",
84
- 10: "Title",
85
- 11: "Document Index",
86
- 12: "Code",
87
- 13: "Checkbox-Selected",
88
- 14: "Checkbox-Unselected",
89
- 15: "Form",
90
- 16: "Key-Value Region",
91
- # Additional classes for compatibility with existing pipeline
92
- 17 : "Table-header",
93
- 18 : "Portfolio-Company-Table"
94
- }
95
-
96
- return model, image_processor, class_names
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-