Spaces:
Runtime error
Runtime error
napatswift
commited on
Commit
•
a03e1e7
1
Parent(s):
992ad70
Update app and weights
Browse files- main.py +8 -0
- model/table-det/config.py +44 -79
- model/table-det/model.pth +2 -2
main.py
CHANGED
@@ -4,6 +4,10 @@ import cv2
|
|
4 |
import sys
|
5 |
import torch
|
6 |
import numpy as np
|
|
|
|
|
|
|
|
|
7 |
|
8 |
print('Loading model...')
|
9 |
device = 'gpu' if torch.cuda.is_available() else 'cpu'
|
@@ -81,12 +85,16 @@ def get_bbox(mask_array):
|
|
81 |
|
82 |
|
83 |
def predict(image_input):
|
|
|
|
|
84 |
# Inference the tables in the image.
|
85 |
result = inference_detector(table_det, image_input)
|
86 |
|
87 |
# Get the masks of the tables.
|
88 |
mask_images = result.pred_instances.masks.cpu().numpy()
|
89 |
scores = result.pred_instances.scores.cpu().numpy()
|
|
|
|
|
90 |
|
91 |
bbox_list = []
|
92 |
|
|
|
4 |
import sys
|
5 |
import torch
|
6 |
import numpy as np
|
7 |
+
import logging
|
8 |
+
|
9 |
+
logging.basicConfig(level=logging.INFO)
|
10 |
+
logger = logging.getLogger(__name__)
|
11 |
|
12 |
print('Loading model...')
|
13 |
device = 'gpu' if torch.cuda.is_available() else 'cpu'
|
|
|
85 |
|
86 |
|
87 |
def predict(image_input):
|
88 |
+
logger.info(f"Image input: {image_input}")
|
89 |
+
|
90 |
# Inference the tables in the image.
|
91 |
result = inference_detector(table_det, image_input)
|
92 |
|
93 |
# Get the masks of the tables.
|
94 |
mask_images = result.pred_instances.masks.cpu().numpy()
|
95 |
scores = result.pred_instances.scores.cpu().numpy()
|
96 |
+
|
97 |
+
logger.info(f"Result: {result}")
|
98 |
|
99 |
bbox_list = []
|
100 |
|
model/table-det/config.py
CHANGED
@@ -2,9 +2,9 @@ model = dict(
|
|
2 |
type='MaskRCNN',
|
3 |
data_preprocessor=dict(
|
4 |
type='DetDataPreprocessor',
|
5 |
-
mean=[
|
6 |
-
std=[
|
7 |
-
bgr_to_rgb=
|
8 |
pad_mask=True,
|
9 |
pad_size_divisor=32),
|
10 |
backbone=dict(
|
@@ -13,10 +13,12 @@ model = dict(
|
|
13 |
num_stages=4,
|
14 |
out_indices=(0, 1, 2, 3),
|
15 |
frozen_stages=1,
|
16 |
-
norm_cfg=dict(type='BN', requires_grad=
|
17 |
norm_eval=True,
|
18 |
-
style='
|
19 |
-
init_cfg=dict(
|
|
|
|
|
20 |
neck=dict(
|
21 |
type='FPN',
|
22 |
in_channels=[256, 512, 1024, 2048],
|
@@ -123,12 +125,21 @@ model = dict(
|
|
123 |
nms=dict(type='nms', iou_threshold=0.5),
|
124 |
max_per_img=100,
|
125 |
mask_thr_binary=0.5)))
|
|
|
|
|
126 |
backend_args = None
|
127 |
train_pipeline = [
|
128 |
dict(type='LoadImageFromFile', backend_args=None),
|
129 |
-
dict(
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
dict(type='RandomFlip', prob=0.5),
|
133 |
dict(type='PackDetInputs')
|
134 |
]
|
@@ -141,82 +152,35 @@ test_pipeline = [
|
|
141 |
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
142 |
'scale_factor'))
|
143 |
]
|
144 |
-
data_root = 'data/table-det-elect66/'
|
145 |
-
metainfo = dict(classes=('Table', ), palette=[(220, 20, 60)])
|
146 |
-
dataset_elect66 = dict(
|
147 |
-
type='CocoDataset',
|
148 |
-
data_root='data/table-det-elect66/',
|
149 |
-
ann_file='result.json',
|
150 |
-
data_prefix=dict(img=''),
|
151 |
-
metainfo=dict(classes=('Table', ), palette=[(220, 20, 60)]),
|
152 |
-
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
153 |
-
pipeline=[
|
154 |
-
dict(type='LoadImageFromFile', backend_args=None),
|
155 |
-
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
156 |
-
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
157 |
-
dict(type='Rotate', level=10),
|
158 |
-
dict(type='RandomFlip', prob=0.5),
|
159 |
-
dict(type='PackDetInputs')
|
160 |
-
])
|
161 |
-
dataset_vote62 = dict(
|
162 |
-
type='CocoDataset',
|
163 |
-
data_root='data/table-det-740/',
|
164 |
-
ann_file='train_coco.json',
|
165 |
-
data_prefix=dict(img=''),
|
166 |
-
metainfo=dict(classes=('Table', ), palette=[(220, 20, 60)]),
|
167 |
-
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
168 |
-
pipeline=[
|
169 |
-
dict(type='LoadImageFromFile', backend_args=None),
|
170 |
-
dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
|
171 |
-
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
172 |
-
dict(type='Rotate', level=10),
|
173 |
-
dict(type='RandomFlip', prob=0.5),
|
174 |
-
dict(type='PackDetInputs')
|
175 |
-
])
|
176 |
train_dataloader = dict(
|
177 |
-
batch_size=
|
178 |
num_workers=2,
|
179 |
persistent_workers=True,
|
180 |
sampler=dict(type='DefaultSampler', shuffle=True),
|
181 |
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
182 |
dataset=dict(
|
183 |
-
type='
|
184 |
-
|
|
|
|
|
|
|
|
|
|
|
185 |
dict(
|
186 |
-
type='
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
metainfo=dict(classes=('Table', ), palette=[(220, 20, 60)]),
|
191 |
-
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
192 |
-
pipeline=[
|
193 |
-
dict(type='LoadImageFromFile', backend_args=None),
|
194 |
-
dict(
|
195 |
-
type='LoadAnnotations', with_bbox=True,
|
196 |
-
with_mask=True),
|
197 |
-
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
198 |
-
dict(type='Rotate', level=10),
|
199 |
-
dict(type='RandomFlip', prob=0.5),
|
200 |
-
dict(type='PackDetInputs')
|
201 |
-
]),
|
202 |
dict(
|
203 |
-
type='
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
type='LoadAnnotations', with_bbox=True,
|
213 |
-
with_mask=True),
|
214 |
-
dict(type='Resize', scale=(1333, 800), keep_ratio=True),
|
215 |
-
dict(type='Rotate', level=10),
|
216 |
-
dict(type='RandomFlip', prob=0.5),
|
217 |
-
dict(type='PackDetInputs')
|
218 |
-
])
|
219 |
-
]))
|
220 |
val_dataloader = dict(
|
221 |
batch_size=1,
|
222 |
num_workers=2,
|
@@ -275,7 +239,7 @@ test_evaluator = dict(
|
|
275 |
metric=['bbox', 'segm'],
|
276 |
format_only=False,
|
277 |
backend_args=None)
|
278 |
-
train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=
|
279 |
val_cfg = dict(type='ValLoop')
|
280 |
test_cfg = dict(type='TestLoop')
|
281 |
param_scheduler = [
|
@@ -296,7 +260,7 @@ auto_scale_lr = dict(enable=False, base_batch_size=16)
|
|
296 |
default_scope = 'mmdet'
|
297 |
default_hooks = dict(
|
298 |
timer=dict(type='IterTimerHook'),
|
299 |
-
logger=dict(type='LoggerHook', interval=
|
300 |
param_scheduler=dict(type='ParamSchedulerHook'),
|
301 |
checkpoint=dict(type='CheckpointHook', interval=5),
|
302 |
sampler_seed=dict(type='DistSamplerSeedHook'),
|
@@ -314,5 +278,6 @@ log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True)
|
|
314 |
log_level = 'INFO'
|
315 |
load_from = None
|
316 |
resume = True
|
|
|
317 |
launcher = 'none'
|
318 |
work_dir = './work_dirs/vote-config'
|
|
|
2 |
type='MaskRCNN',
|
3 |
data_preprocessor=dict(
|
4 |
type='DetDataPreprocessor',
|
5 |
+
mean=[103.53, 116.28, 123.675],
|
6 |
+
std=[1.0, 1.0, 1.0],
|
7 |
+
bgr_to_rgb=False,
|
8 |
pad_mask=True,
|
9 |
pad_size_divisor=32),
|
10 |
backbone=dict(
|
|
|
13 |
num_stages=4,
|
14 |
out_indices=(0, 1, 2, 3),
|
15 |
frozen_stages=1,
|
16 |
+
norm_cfg=dict(type='BN', requires_grad=False),
|
17 |
norm_eval=True,
|
18 |
+
style='caffe',
|
19 |
+
init_cfg=dict(
|
20 |
+
type='Pretrained',
|
21 |
+
checkpoint='open-mmlab://detectron2/resnet50_caffe')),
|
22 |
neck=dict(
|
23 |
type='FPN',
|
24 |
in_channels=[256, 512, 1024, 2048],
|
|
|
125 |
nms=dict(type='nms', iou_threshold=0.5),
|
126 |
max_per_img=100,
|
127 |
mask_thr_binary=0.5)))
|
128 |
+
dataset_type = 'CocoDataset'
|
129 |
+
data_root = 'data/table-det-elect66/'
|
130 |
backend_args = None
|
131 |
train_pipeline = [
|
132 |
dict(type='LoadImageFromFile', backend_args=None),
|
133 |
+
dict(
|
134 |
+
type='LoadAnnotations',
|
135 |
+
with_bbox=True,
|
136 |
+
with_mask=True,
|
137 |
+
poly2mask=False),
|
138 |
+
dict(
|
139 |
+
type='RandomChoiceResize',
|
140 |
+
scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736),
|
141 |
+
(1333, 768), (1333, 800)],
|
142 |
+
keep_ratio=True),
|
143 |
dict(type='RandomFlip', prob=0.5),
|
144 |
dict(type='PackDetInputs')
|
145 |
]
|
|
|
152 |
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
|
153 |
'scale_factor'))
|
154 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
train_dataloader = dict(
|
156 |
+
batch_size=8,
|
157 |
num_workers=2,
|
158 |
persistent_workers=True,
|
159 |
sampler=dict(type='DefaultSampler', shuffle=True),
|
160 |
batch_sampler=dict(type='AspectRatioBatchSampler'),
|
161 |
dataset=dict(
|
162 |
+
type='CocoDataset',
|
163 |
+
data_root='data/table-det-elect66/',
|
164 |
+
ann_file='result.json',
|
165 |
+
data_prefix=dict(img=''),
|
166 |
+
filter_cfg=dict(filter_empty_gt=True, min_size=32),
|
167 |
+
pipeline=[
|
168 |
+
dict(type='LoadImageFromFile', backend_args=None),
|
169 |
dict(
|
170 |
+
type='LoadAnnotations',
|
171 |
+
with_bbox=True,
|
172 |
+
with_mask=True,
|
173 |
+
poly2mask=False),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
dict(
|
175 |
+
type='RandomChoiceResize',
|
176 |
+
scales=[(1333, 640), (1333, 672), (1333, 704), (1333, 736),
|
177 |
+
(1333, 768), (1333, 800)],
|
178 |
+
keep_ratio=True),
|
179 |
+
dict(type='RandomFlip', prob=0.5),
|
180 |
+
dict(type='PackDetInputs')
|
181 |
+
],
|
182 |
+
backend_args=None,
|
183 |
+
metainfo=dict(classes=('Table', ), palette=[(220, 20, 60)])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
val_dataloader = dict(
|
185 |
batch_size=1,
|
186 |
num_workers=2,
|
|
|
239 |
metric=['bbox', 'segm'],
|
240 |
format_only=False,
|
241 |
backend_args=None)
|
242 |
+
train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=70, val_interval=5)
|
243 |
val_cfg = dict(type='ValLoop')
|
244 |
test_cfg = dict(type='TestLoop')
|
245 |
param_scheduler = [
|
|
|
260 |
default_scope = 'mmdet'
|
261 |
default_hooks = dict(
|
262 |
timer=dict(type='IterTimerHook'),
|
263 |
+
logger=dict(type='LoggerHook', interval=50),
|
264 |
param_scheduler=dict(type='ParamSchedulerHook'),
|
265 |
checkpoint=dict(type='CheckpointHook', interval=5),
|
266 |
sampler_seed=dict(type='DistSamplerSeedHook'),
|
|
|
278 |
log_level = 'INFO'
|
279 |
load_from = None
|
280 |
resume = True
|
281 |
+
metainfo = dict(classes=('Table', ), palette=[(220, 20, 60)])
|
282 |
launcher = 'none'
|
283 |
work_dir = './work_dirs/vote-config'
|
model/table-det/model.pth
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e84722e31515bf2415bec7fafbb3f2d9ebbf058e7003b91d798e4cdb9219a58e
|
3 |
+
size 351647241
|