bachpc commited on
Commit
fff539b
1 Parent(s): 45b51fc

Update new weights

Browse files
app.py CHANGED
@@ -61,13 +61,13 @@ detection_class_thresholds = {
61
  'no object': 10
62
  }
63
  structure_class_thresholds = {
64
- 'table': 0.42,
65
- 'table column': 0.56,
66
- 'table row': 0.5,
67
- 'table column header': 0.38,
68
- 'table projected row header': 0.27,
69
- 'table spanning cell': 0.4,
70
- 'no object': 10
71
  }
72
 
73
 
@@ -95,7 +95,7 @@ def table_structure(pil_img, imgsz=640):
95
  return result
96
 
97
 
98
- def crop_image(pil_img, detection_result, padding=30):
99
  crop_images = []
100
  image = PIL_to_cv(pil_img)
101
  width = image.shape[1]
@@ -118,10 +118,13 @@ def crop_image(pil_img, detection_result, padding=30):
118
  y2 = int((min_y + h / 2) * height)
119
  # print(x1, y1, x2, y2)
120
 
121
- x1_pad = max(0, x1 - padding)
122
- y1_pad = max(0, y1 - padding)
123
- x2_pad = min(width, x2 + padding)
124
- y2_pad = min(height, y2 + padding)
 
 
 
125
 
126
  crop_image = image[y1_pad:y2_pad, x1_pad:x2_pad, :]
127
  crop_image = cv_to_PIL(crop_image)
@@ -131,7 +134,15 @@ def crop_image(pil_img, detection_result, padding=30):
131
  crop_images.append(crop_image)
132
 
133
  cv2.rectangle(image, (x1, y1), (x2, y2), color=(0, 0, 255), thickness=2)
134
- cv2.putText(image, f'{score:.2f}', (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=(255, 0, 0))
 
 
 
 
 
 
 
 
135
 
136
  return crop_images, cv_to_PIL(image)
137
 
 
61
  'no object': 10
62
  }
63
  structure_class_thresholds = {
64
+ "table": 0.45,
65
+ "table column": 0.6,
66
+ "table row": 0.5,
67
+ "table column header": 0.4,
68
+ "table projected row header": 0.3,
69
+ "table spanning cell": 0.5,
70
+ "no object": 10
71
  }
72
 
73
 
 
95
  return result
96
 
97
 
98
+ def crop_image(pil_img, detection_result):
99
  crop_images = []
100
  image = PIL_to_cv(pil_img)
101
  width = image.shape[1]
 
118
  y2 = int((min_y + h / 2) * height)
119
  # print(x1, y1, x2, y2)
120
 
121
+ padding_x = max(int(0.02 * width), 30)
122
+ padding_y = max(int(0.02 * height), 30)
123
+
124
+ x1_pad = max(0, x1 - padding_x)
125
+ y1_pad = max(0, y1 - padding_y)
126
+ x2_pad = min(width, x2 + padding_x)
127
+ y2_pad = min(height, y2 + padding_y)
128
 
129
  crop_image = image[y1_pad:y2_pad, x1_pad:x2_pad, :]
130
  crop_image = cv_to_PIL(crop_image)
 
134
  crop_images.append(crop_image)
135
 
136
  cv2.rectangle(image, (x1, y1), (x2, y2), color=(0, 0, 255), thickness=2)
137
+
138
+ label = f'{detection_class_names[class_id]} {score:.2f}'
139
+
140
+ lw = max(round(sum(image.shape) / 2 * 0.003), 2)
141
+ fontScale = lw / 3
142
+ thickness = max(lw - 1, 1)
143
+ w_label, h_label = cv2.getTextSize(label, 0, fontScale=fontScale, thickness=thickness)[0]
144
+ cv2.rectangle(image, (x1, y1), (x1 + w_label, y1 - h_label - 3), (255, 0, 0), -1, cv2.LINE_AA)
145
+ cv2.putText(image, label, (x1, y1 - 2), cv2.FONT_HERSHEY_SIMPLEX, fontScale=fontScale, thickness=thickness, lineType=cv2.LINE_AA)
146
 
147
  return crop_images, cv_to_PIL(image)
148
 
weights/detection_wts.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:32127c7362c16c5839cb95c942cbc9ad1412fd953eb4b0b93758a49f01e312cb
3
- size 14397685
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65185c6453ed61648f13dd26af441bd194ec8b37ec52e0facff71607a2c45ece
3
+ size 42156713
weights/detection_wts_old.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:32127c7362c16c5839cb95c942cbc9ad1412fd953eb4b0b93758a49f01e312cb
3
+ size 14397685
weights/structure_wts.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:46121ab2f4aba48a7d38624c861658ffeaacd0f305e95efcf66cb017e588b700
3
- size 14371957
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77d76138a73f4c8173356018a2240510f34046c1e0d366de2a2981bfbe0ea55a
3
+ size 42146857
weights/structure_wts_old.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:46121ab2f4aba48a7d38624c861658ffeaacd0f305e95efcf66cb017e588b700
3
+ size 14371957