deepdoctection 0.31__py3-none-any.whl → 0.32__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of deepdoctection might be problematic. Click here for more details.
- deepdoctection/__init__.py +35 -28
- deepdoctection/analyzer/dd.py +30 -24
- deepdoctection/configs/conf_dd_one.yaml +34 -31
- deepdoctection/datapoint/annotation.py +2 -1
- deepdoctection/datapoint/box.py +2 -1
- deepdoctection/datapoint/image.py +13 -7
- deepdoctection/datapoint/view.py +95 -24
- deepdoctection/datasets/__init__.py +1 -4
- deepdoctection/datasets/adapter.py +5 -2
- deepdoctection/datasets/base.py +5 -3
- deepdoctection/datasets/info.py +2 -2
- deepdoctection/datasets/instances/doclaynet.py +3 -2
- deepdoctection/datasets/instances/fintabnet.py +2 -1
- deepdoctection/datasets/instances/funsd.py +2 -1
- deepdoctection/datasets/instances/iiitar13k.py +5 -2
- deepdoctection/datasets/instances/layouttest.py +2 -1
- deepdoctection/datasets/instances/publaynet.py +2 -2
- deepdoctection/datasets/instances/pubtables1m.py +6 -3
- deepdoctection/datasets/instances/pubtabnet.py +2 -1
- deepdoctection/datasets/instances/rvlcdip.py +2 -1
- deepdoctection/datasets/instances/xfund.py +2 -1
- deepdoctection/eval/__init__.py +1 -4
- deepdoctection/eval/cocometric.py +2 -1
- deepdoctection/eval/eval.py +17 -13
- deepdoctection/eval/tedsmetric.py +14 -11
- deepdoctection/eval/tp_eval_callback.py +9 -3
- deepdoctection/extern/__init__.py +2 -7
- deepdoctection/extern/d2detect.py +24 -32
- deepdoctection/extern/deskew.py +4 -2
- deepdoctection/extern/doctrocr.py +75 -81
- deepdoctection/extern/fastlang.py +4 -2
- deepdoctection/extern/hfdetr.py +22 -28
- deepdoctection/extern/hflayoutlm.py +335 -103
- deepdoctection/extern/hflm.py +225 -0
- deepdoctection/extern/model.py +56 -47
- deepdoctection/extern/pdftext.py +8 -4
- deepdoctection/extern/pt/__init__.py +1 -3
- deepdoctection/extern/pt/nms.py +6 -2
- deepdoctection/extern/pt/ptutils.py +27 -19
- deepdoctection/extern/texocr.py +4 -2
- deepdoctection/extern/tp/tfutils.py +43 -9
- deepdoctection/extern/tp/tpcompat.py +10 -7
- deepdoctection/extern/tp/tpfrcnn/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/common.py +7 -3
- deepdoctection/extern/tp/tpfrcnn/config/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/config/config.py +9 -6
- deepdoctection/extern/tp/tpfrcnn/modeling/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/modeling/backbone.py +17 -7
- deepdoctection/extern/tp/tpfrcnn/modeling/generalized_rcnn.py +12 -6
- deepdoctection/extern/tp/tpfrcnn/modeling/model_box.py +9 -4
- deepdoctection/extern/tp/tpfrcnn/modeling/model_cascade.py +8 -5
- deepdoctection/extern/tp/tpfrcnn/modeling/model_fpn.py +16 -11
- deepdoctection/extern/tp/tpfrcnn/modeling/model_frcnn.py +17 -10
- deepdoctection/extern/tp/tpfrcnn/modeling/model_mrcnn.py +14 -8
- deepdoctection/extern/tp/tpfrcnn/modeling/model_rpn.py +15 -10
- deepdoctection/extern/tp/tpfrcnn/predict.py +9 -4
- deepdoctection/extern/tp/tpfrcnn/preproc.py +7 -3
- deepdoctection/extern/tp/tpfrcnn/utils/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/utils/box_ops.py +10 -2
- deepdoctection/extern/tpdetect.py +5 -8
- deepdoctection/mapper/__init__.py +3 -8
- deepdoctection/mapper/d2struct.py +8 -6
- deepdoctection/mapper/hfstruct.py +6 -1
- deepdoctection/mapper/laylmstruct.py +163 -20
- deepdoctection/mapper/maputils.py +3 -1
- deepdoctection/mapper/misc.py +6 -3
- deepdoctection/mapper/tpstruct.py +2 -2
- deepdoctection/pipe/__init__.py +1 -1
- deepdoctection/pipe/common.py +11 -9
- deepdoctection/pipe/concurrency.py +2 -1
- deepdoctection/pipe/layout.py +3 -1
- deepdoctection/pipe/lm.py +32 -64
- deepdoctection/pipe/order.py +142 -35
- deepdoctection/pipe/refine.py +8 -14
- deepdoctection/pipe/{cell.py → sub_layout.py} +1 -1
- deepdoctection/train/__init__.py +6 -12
- deepdoctection/train/d2_frcnn_train.py +21 -16
- deepdoctection/train/hf_detr_train.py +18 -11
- deepdoctection/train/hf_layoutlm_train.py +118 -101
- deepdoctection/train/tp_frcnn_train.py +21 -19
- deepdoctection/utils/env_info.py +41 -117
- deepdoctection/utils/logger.py +1 -0
- deepdoctection/utils/mocks.py +93 -0
- deepdoctection/utils/settings.py +1 -0
- deepdoctection/utils/viz.py +4 -3
- {deepdoctection-0.31.dist-info → deepdoctection-0.32.dist-info}/METADATA +27 -18
- deepdoctection-0.32.dist-info/RECORD +146 -0
- deepdoctection-0.31.dist-info/RECORD +0 -144
- {deepdoctection-0.31.dist-info → deepdoctection-0.32.dist-info}/LICENSE +0 -0
- {deepdoctection-0.31.dist-info → deepdoctection-0.32.dist-info}/WHEEL +0 -0
- {deepdoctection-0.31.dist-info → deepdoctection-0.32.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# File: __init__.py
|
|
3
|
+
|
|
4
|
+
# Copyright 2021 Dr. Janis Meyer. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
Init file for code for Tensorpack's FRCNN configs
|
|
20
|
+
"""
|
|
@@ -191,16 +191,19 @@ import os
|
|
|
191
191
|
from typing import List, Mapping, Tuple
|
|
192
192
|
|
|
193
193
|
import numpy as np
|
|
194
|
-
from
|
|
195
|
-
from tensorpack.utils import logger # pylint: disable=E0401
|
|
196
|
-
|
|
197
|
-
# pylint: disable=import-error
|
|
198
|
-
from tensorpack.utils.gpu import get_num_gpu
|
|
194
|
+
from lazy_imports import try_import
|
|
199
195
|
|
|
200
196
|
from .....utils.metacfg import AttrDict
|
|
201
197
|
from .....utils.settings import ObjectTypes
|
|
202
198
|
|
|
203
|
-
|
|
199
|
+
with try_import() as import_guard:
|
|
200
|
+
from tensorpack.tfutils import collect_env_info # pylint: disable=E0401
|
|
201
|
+
from tensorpack.utils import logger # pylint: disable=E0401
|
|
202
|
+
|
|
203
|
+
# pylint: disable=import-error
|
|
204
|
+
from tensorpack.utils.gpu import get_num_gpu
|
|
205
|
+
|
|
206
|
+
# pylint: enable=import-error
|
|
204
207
|
|
|
205
208
|
|
|
206
209
|
__all__ = ["train_frcnn_config", "model_frcnn_config"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# File: __init__.py
|
|
3
|
+
|
|
4
|
+
# Copyright 2021 Dr. Janis Meyer. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
Init file for code for Tensorpack's FRCNN configs
|
|
20
|
+
"""
|
|
@@ -12,22 +12,30 @@ This file is modified from
|
|
|
12
12
|
from contextlib import ExitStack, contextmanager
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
|
+
from lazy_imports import try_import
|
|
15
16
|
|
|
16
17
|
# pylint: disable=import-error
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
from tensorpack
|
|
21
|
-
from tensorpack.
|
|
18
|
+
|
|
19
|
+
with try_import() as import_guard:
|
|
20
|
+
import tensorflow as tf
|
|
21
|
+
from tensorpack import tfv1
|
|
22
|
+
from tensorpack.models import BatchNorm, Conv2D, MaxPooling, layer_register
|
|
23
|
+
from tensorpack.tfutils import argscope
|
|
24
|
+
from tensorpack.tfutils.varreplace import custom_getter_scope, freeze_variables
|
|
22
25
|
|
|
23
26
|
# pylint: enable=import-error
|
|
24
27
|
|
|
28
|
+
if not import_guard.is_successful():
|
|
29
|
+
from .....utils.mocks import layer_register
|
|
30
|
+
|
|
25
31
|
|
|
26
32
|
@layer_register(log_shape=True)
|
|
27
|
-
def GroupNorm(x, group=32, gamma_initializer=
|
|
33
|
+
def GroupNorm(x, group=32, gamma_initializer=None):
|
|
28
34
|
"""
|
|
29
35
|
More code that reproduces the paper can be found at <https://github.com/ppwwyyxx/GroupNorm-reproduce/>.
|
|
30
36
|
"""
|
|
37
|
+
if gamma_initializer is None:
|
|
38
|
+
gamma_initializer = tf.constant_initializer(1.0)
|
|
31
39
|
shape = x.get_shape().as_list()
|
|
32
40
|
ndims = len(shape)
|
|
33
41
|
assert ndims == 4, shape
|
|
@@ -153,7 +161,7 @@ def get_norm(cfg, zero_init=False):
|
|
|
153
161
|
return lambda x: norm(layer_name, x, gamma_initializer=tf.zeros_initializer() if zero_init else None)
|
|
154
162
|
|
|
155
163
|
|
|
156
|
-
def resnet_shortcut(l, n_out, stride, activation=
|
|
164
|
+
def resnet_shortcut(l, n_out, stride, activation=None):
|
|
157
165
|
"""
|
|
158
166
|
Defining the skip connection in bottleneck
|
|
159
167
|
|
|
@@ -163,6 +171,8 @@ def resnet_shortcut(l, n_out, stride, activation=tf.identity):
|
|
|
163
171
|
:param activation: An activation function
|
|
164
172
|
:return: tf.Tensor
|
|
165
173
|
"""
|
|
174
|
+
if activation is None:
|
|
175
|
+
activation = tf.identity
|
|
166
176
|
n_in = l.shape[1]
|
|
167
177
|
if n_in != n_out: # change dimension when channel is not the same
|
|
168
178
|
return Conv2D("convshortcut", l, n_out, 1, strides=stride, activation=activation) # pylint: disable=E1124
|
|
@@ -9,12 +9,8 @@ This file is modified from
|
|
|
9
9
|
<https://github.com/tensorpack/tensorpack/blob/master/examples/FasterRCNN/modeling/generalized_rcnn.py>
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from tensorpack import tfv1
|
|
15
|
-
from tensorpack.models import l2_regularizer, regularize_cost
|
|
16
|
-
from tensorpack.tfutils import optimizer
|
|
17
|
-
from tensorpack.tfutils.summary import add_moving_summary
|
|
12
|
+
|
|
13
|
+
from lazy_imports import try_import
|
|
18
14
|
|
|
19
15
|
from ...tpcompat import ModelDescWithConfig
|
|
20
16
|
from ..utils.box_ops import area as tf_area
|
|
@@ -40,6 +36,16 @@ from .model_frcnn import (
|
|
|
40
36
|
from .model_mrcnn import maskrcnn_loss, unpackbits_masks
|
|
41
37
|
from .model_rpn import rpn_head
|
|
42
38
|
|
|
39
|
+
with try_import() as import_guard:
|
|
40
|
+
# pylint: disable=import-error
|
|
41
|
+
import tensorflow as tf
|
|
42
|
+
from tensorpack import tfv1
|
|
43
|
+
from tensorpack.models import l2_regularizer, regularize_cost
|
|
44
|
+
from tensorpack.tfutils import optimizer
|
|
45
|
+
from tensorpack.tfutils.summary import add_moving_summary
|
|
46
|
+
|
|
47
|
+
# pylint: enable=import-error
|
|
48
|
+
|
|
43
49
|
|
|
44
50
|
class GeneralizedRCNN(ModelDescWithConfig):
|
|
45
51
|
"""
|
|
@@ -11,12 +11,17 @@ This file is modified from
|
|
|
11
11
|
from collections import namedtuple
|
|
12
12
|
|
|
13
13
|
import numpy as np
|
|
14
|
+
from lazy_imports import try_import
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
with try_import() as import_guard:
|
|
17
|
+
# pylint: disable=import-error
|
|
18
|
+
import tensorflow as tf
|
|
19
|
+
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
18
20
|
|
|
19
|
-
# pylint: enable=import-error
|
|
21
|
+
# pylint: enable=import-error
|
|
22
|
+
|
|
23
|
+
if not import_guard.is_successful():
|
|
24
|
+
from .....utils.mocks import under_name_scope
|
|
20
25
|
|
|
21
26
|
|
|
22
27
|
@under_name_scope()
|
|
@@ -9,17 +9,20 @@ This file is modified from
|
|
|
9
9
|
<https://github.com/tensorpack/tensorpack/blob/master/examples/FasterRCNN/modeling/model_cascade.py>
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
import tensorflow as tf
|
|
14
|
-
from tensorpack import tfv1
|
|
15
|
-
from tensorpack.tfutils import get_current_tower_context
|
|
12
|
+
from lazy_imports import try_import
|
|
16
13
|
|
|
17
14
|
from ..utils.box_ops import area as tf_area
|
|
18
15
|
from ..utils.box_ops import pairwise_iou
|
|
19
16
|
from .model_box import clip_boxes
|
|
20
17
|
from .model_frcnn import BoxProposals, FastRCNNHead, fastrcnn_outputs
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
with try_import() as import_guard:
|
|
20
|
+
# pylint: disable=import-error
|
|
21
|
+
import tensorflow as tf
|
|
22
|
+
from tensorpack import tfv1
|
|
23
|
+
from tensorpack.tfutils import get_current_tower_context
|
|
24
|
+
|
|
25
|
+
# pylint: enable=import-error
|
|
23
26
|
|
|
24
27
|
|
|
25
28
|
class CascadeRCNNHead:
|
|
@@ -12,23 +12,28 @@ This file is modified from
|
|
|
12
12
|
import itertools
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
|
-
|
|
16
|
-
# pylint: disable=import-error
|
|
17
|
-
import tensorflow as tf
|
|
18
|
-
from tensorpack import tfv1
|
|
19
|
-
from tensorpack.models import Conv2D, FixedUnPooling, MaxPooling, layer_register
|
|
20
|
-
from tensorpack.tfutils.argscope import argscope
|
|
21
|
-
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
22
|
-
from tensorpack.tfutils.summary import add_moving_summary
|
|
23
|
-
from tensorpack.tfutils.tower import get_current_tower_context
|
|
24
|
-
from tensorpack.utils.argtools import memoized
|
|
15
|
+
from lazy_imports import try_import
|
|
25
16
|
|
|
26
17
|
from ..utils.box_ops import area as tf_area
|
|
27
18
|
from .backbone import GroupNorm
|
|
28
19
|
from .model_box import roi_align
|
|
29
20
|
from .model_rpn import generate_rpn_proposals, get_all_anchors, rpn_losses
|
|
30
21
|
|
|
31
|
-
|
|
22
|
+
with try_import() as import_guard:
|
|
23
|
+
# pylint: disable=import-error
|
|
24
|
+
import tensorflow as tf
|
|
25
|
+
from tensorpack import tfv1
|
|
26
|
+
from tensorpack.models import Conv2D, FixedUnPooling, MaxPooling, layer_register
|
|
27
|
+
from tensorpack.tfutils.argscope import argscope
|
|
28
|
+
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
29
|
+
from tensorpack.tfutils.summary import add_moving_summary
|
|
30
|
+
from tensorpack.tfutils.tower import get_current_tower_context
|
|
31
|
+
from tensorpack.utils.argtools import memoized
|
|
32
|
+
|
|
33
|
+
# pylint: enable=import-error
|
|
34
|
+
|
|
35
|
+
if not import_guard.is_successful():
|
|
36
|
+
from .....utils.mocks import layer_register, memoized, under_name_scope
|
|
32
37
|
|
|
33
38
|
|
|
34
39
|
@layer_register(log_shape=True)
|
|
@@ -8,21 +8,28 @@
|
|
|
8
8
|
This file is modified from
|
|
9
9
|
<https://github.com/tensorpack/tensorpack/blob/master/examples/FasterRCNN/modeling/model_frcnn.py>
|
|
10
10
|
"""
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
from tensorpack import tfv1
|
|
14
|
-
from tensorpack.models import Conv2D, FullyConnected, layer_register
|
|
15
|
-
from tensorpack.tfutils.argscope import argscope
|
|
16
|
-
from tensorpack.tfutils.common import get_tf_version_tuple
|
|
17
|
-
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
18
|
-
from tensorpack.tfutils.summary import add_moving_summary
|
|
19
|
-
from tensorpack.utils.argtools import memoized_method
|
|
11
|
+
|
|
12
|
+
from lazy_imports import try_import
|
|
20
13
|
|
|
21
14
|
from ..utils.box_ops import pairwise_iou
|
|
22
15
|
from .backbone import GroupNorm
|
|
23
16
|
from .model_box import decode_bbox_target, encode_bbox_target
|
|
24
17
|
|
|
25
|
-
|
|
18
|
+
with try_import() as import_guard:
|
|
19
|
+
# pylint: disable=import-error
|
|
20
|
+
import tensorflow as tf
|
|
21
|
+
from tensorpack import tfv1
|
|
22
|
+
from tensorpack.models import Conv2D, FullyConnected, layer_register
|
|
23
|
+
from tensorpack.tfutils.argscope import argscope
|
|
24
|
+
from tensorpack.tfutils.common import get_tf_version_tuple
|
|
25
|
+
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
26
|
+
from tensorpack.tfutils.summary import add_moving_summary
|
|
27
|
+
from tensorpack.utils.argtools import memoized_method
|
|
28
|
+
|
|
29
|
+
# pylint: enable=import-error
|
|
30
|
+
|
|
31
|
+
if not import_guard.is_successful():
|
|
32
|
+
from .....utils.mocks import layer_register, memoized_method, under_name_scope
|
|
26
33
|
|
|
27
34
|
|
|
28
35
|
@under_name_scope()
|
|
@@ -9,17 +9,23 @@ This file is modified from
|
|
|
9
9
|
<https://github.com/tensorpack/tensorpack/blob/master/examples/FasterRCNN/modeling/model_mrcnn.py>
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
import tensorflow as tf
|
|
14
|
-
from tensorpack.models import Conv2D, Conv2DTranspose, layer_register
|
|
15
|
-
from tensorpack.tfutils.argscope import argscope
|
|
16
|
-
from tensorpack.tfutils.common import get_tf_version_tuple
|
|
17
|
-
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
18
|
-
from tensorpack.tfutils.summary import add_moving_summary
|
|
12
|
+
from lazy_imports import try_import
|
|
19
13
|
|
|
20
14
|
from .backbone import GroupNorm
|
|
21
15
|
|
|
22
|
-
|
|
16
|
+
with try_import() as import_guard:
|
|
17
|
+
# pylint: disable=import-error
|
|
18
|
+
import tensorflow as tf
|
|
19
|
+
from tensorpack.models import Conv2D, Conv2DTranspose, layer_register
|
|
20
|
+
from tensorpack.tfutils.argscope import argscope
|
|
21
|
+
from tensorpack.tfutils.common import get_tf_version_tuple
|
|
22
|
+
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
23
|
+
from tensorpack.tfutils.summary import add_moving_summary
|
|
24
|
+
|
|
25
|
+
# pylint: enable=import-error
|
|
26
|
+
|
|
27
|
+
if not import_guard.is_successful():
|
|
28
|
+
from .....utils.mocks import layer_register, under_name_scope
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
@under_name_scope()
|
|
@@ -10,19 +10,24 @@ This file is modified from
|
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
import numpy as np
|
|
13
|
-
|
|
14
|
-
# pylint: disable=import-error
|
|
15
|
-
import tensorflow as tf
|
|
16
|
-
from tensorpack import tfv1
|
|
17
|
-
from tensorpack.models import Conv2D, layer_register
|
|
18
|
-
from tensorpack.tfutils.argscope import argscope
|
|
19
|
-
from tensorpack.tfutils.scope_utils import auto_reuse_variable_scope, under_name_scope
|
|
20
|
-
from tensorpack.tfutils.summary import add_moving_summary
|
|
21
|
-
from tensorpack.utils.argtools import memoized
|
|
13
|
+
from lazy_imports import try_import
|
|
22
14
|
|
|
23
15
|
from .model_box import clip_boxes
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
with try_import() as import_guard:
|
|
18
|
+
# pylint: disable=import-error
|
|
19
|
+
import tensorflow as tf
|
|
20
|
+
from tensorpack import tfv1
|
|
21
|
+
from tensorpack.models import Conv2D, layer_register
|
|
22
|
+
from tensorpack.tfutils.argscope import argscope
|
|
23
|
+
from tensorpack.tfutils.scope_utils import auto_reuse_variable_scope, under_name_scope
|
|
24
|
+
from tensorpack.tfutils.summary import add_moving_summary
|
|
25
|
+
from tensorpack.utils.argtools import memoized
|
|
26
|
+
|
|
27
|
+
# pylint: enable=import-error
|
|
28
|
+
|
|
29
|
+
if not import_guard.is_successful():
|
|
30
|
+
from .....utils.mocks import auto_reuse_variable_scope, layer_register, memoized, under_name_scope
|
|
26
31
|
|
|
27
32
|
|
|
28
33
|
@layer_register(log_shape=True)
|
|
@@ -8,21 +8,26 @@
|
|
|
8
8
|
This file is modified from
|
|
9
9
|
<https://github.com/tensorpack/tensorpack/blob/master/examples/FasterRCNN/predict.py>
|
|
10
10
|
"""
|
|
11
|
+
from __future__ import annotations
|
|
11
12
|
|
|
12
13
|
from typing import List
|
|
13
14
|
|
|
14
|
-
import cv2
|
|
15
15
|
import numpy as np
|
|
16
|
-
from
|
|
16
|
+
from lazy_imports import try_import
|
|
17
17
|
|
|
18
|
-
from ....utils.file_utils import scipy_available
|
|
19
18
|
from ....utils.transform import InferenceResize
|
|
20
19
|
from ...base import DetectionResult
|
|
21
20
|
from .common import clip_boxes
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
with try_import() as import_guard:
|
|
23
|
+
from tensorpack.predict.base import OfflinePredictor # pylint: disable=E0401
|
|
24
|
+
|
|
25
|
+
with try_import() as sp_import_guard:
|
|
24
26
|
from scipy import interpolate
|
|
25
27
|
|
|
28
|
+
with try_import() as cv2_import_guard:
|
|
29
|
+
import cv2
|
|
30
|
+
|
|
26
31
|
|
|
27
32
|
def _scale_box(box, scale):
|
|
28
33
|
w_half = (box[2] - box[0]) * 0.5
|
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
This file is modified from
|
|
9
9
|
<https://github.com/tensorpack/tensorpack/blob/1a79d595f7eda9dc9dc8428f4461680ed2222ab6/examples/FasterRCNN/data.py>
|
|
10
10
|
"""
|
|
11
|
+
from __future__ import annotations
|
|
11
12
|
|
|
12
13
|
from typing import Any, List, Optional, Tuple
|
|
13
14
|
|
|
14
15
|
import numpy as np
|
|
15
|
-
|
|
16
|
-
# pylint: disable=import-error
|
|
17
|
-
from tensorpack.dataflow.imgaug import AugmentorList, ImageAugmentor
|
|
16
|
+
from lazy_imports import try_import
|
|
18
17
|
|
|
19
18
|
from ....datapoint.convert import box_to_point4, point4_to_box
|
|
20
19
|
from ....utils.detection_types import ImageType, JsonDict
|
|
@@ -25,6 +24,11 @@ from .modeling.model_fpn import get_all_anchors_fpn
|
|
|
25
24
|
from .utils.np_box_ops import area as np_area
|
|
26
25
|
from .utils.np_box_ops import ioa as np_ioa
|
|
27
26
|
|
|
27
|
+
# pylint: disable=import-error
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
with try_import() as import_guard:
|
|
31
|
+
from tensorpack.dataflow.imgaug import AugmentorList, ImageAugmentor
|
|
28
32
|
# pylint: enable=import-error
|
|
29
33
|
|
|
30
34
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# File: __init__.py
|
|
3
|
+
|
|
4
|
+
# Copyright 2021 Dr. Janis Meyer. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
Init file for code for Tensorpack utils
|
|
20
|
+
"""
|
|
@@ -15,8 +15,16 @@ and
|
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
17
|
# pylint: disable=import-error
|
|
18
|
-
|
|
19
|
-
from
|
|
18
|
+
|
|
19
|
+
from lazy_imports import try_import
|
|
20
|
+
|
|
21
|
+
with try_import() as tf_import_guard:
|
|
22
|
+
import tensorflow as tf
|
|
23
|
+
from tensorpack.tfutils.scope_utils import under_name_scope
|
|
24
|
+
|
|
25
|
+
if not tf_import_guard.is_successful():
|
|
26
|
+
from .....utils.mocks import under_name_scope
|
|
27
|
+
|
|
20
28
|
|
|
21
29
|
# pylint: enable=import-error
|
|
22
30
|
|
|
@@ -25,16 +25,14 @@ from pathlib import Path
|
|
|
25
25
|
from typing import Dict, List, Mapping, Optional, Sequence, Union
|
|
26
26
|
|
|
27
27
|
from ..utils.detection_types import ImageType, Requirement
|
|
28
|
-
from ..utils.file_utils import get_tensorflow_requirement, get_tensorpack_requirement
|
|
28
|
+
from ..utils.file_utils import get_tensorflow_requirement, get_tensorpack_requirement
|
|
29
29
|
from ..utils.metacfg import set_config_by_yaml
|
|
30
30
|
from ..utils.settings import ObjectTypes, TypeOrStr, get_type
|
|
31
31
|
from .base import DetectionResult, ObjectDetector, PredictorBase
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
from .tp.tpfrcnn.modeling.generalized_rcnn import ResNetFPNModel
|
|
37
|
-
from .tp.tpfrcnn.predict import tp_predict_image
|
|
32
|
+
from .tp.tpcompat import TensorpackPredictor
|
|
33
|
+
from .tp.tpfrcnn.config.config import model_frcnn_config
|
|
34
|
+
from .tp.tpfrcnn.modeling.generalized_rcnn import ResNetFPNModel
|
|
35
|
+
from .tp.tpfrcnn.predict import tp_predict_image
|
|
38
36
|
|
|
39
37
|
|
|
40
38
|
class TPFrcnnDetectorMixin(ObjectDetector, ABC):
|
|
@@ -140,7 +138,6 @@ class TPFrcnnDetector(TensorpackPredictor, TPFrcnnDetectorMixin):
|
|
|
140
138
|
|
|
141
139
|
self.name = self.get_name(path_weights, self._model.cfg.TAG)
|
|
142
140
|
self.model_id = self.get_model_id()
|
|
143
|
-
assert self._number_gpus > 0, "Model only support inference with GPU"
|
|
144
141
|
|
|
145
142
|
@staticmethod
|
|
146
143
|
def get_wrapped_model(
|
|
@@ -20,9 +20,11 @@ Contains everything that is related to transformation between datapoints
|
|
|
20
20
|
"""
|
|
21
21
|
from typing import Callable
|
|
22
22
|
|
|
23
|
-
from ..utils.file_utils import pytorch_available, transformers_available
|
|
24
23
|
from .cats import *
|
|
25
24
|
from .cocostruct import *
|
|
25
|
+
from .d2struct import *
|
|
26
|
+
from .hfstruct import *
|
|
27
|
+
from .laylmstruct import *
|
|
26
28
|
from .maputils import *
|
|
27
29
|
from .match import *
|
|
28
30
|
from .misc import *
|
|
@@ -32,12 +34,5 @@ from .pubstruct import *
|
|
|
32
34
|
from .tpstruct import *
|
|
33
35
|
from .xfundstruct import *
|
|
34
36
|
|
|
35
|
-
if pytorch_available() and transformers_available():
|
|
36
|
-
from .hfstruct import *
|
|
37
|
-
from .laylmstruct import *
|
|
38
|
-
|
|
39
|
-
if pytorch_available():
|
|
40
|
-
from .d2struct import *
|
|
41
|
-
|
|
42
37
|
# Mapper
|
|
43
38
|
Mapper = Callable[[Image], Optional[Image]]
|
|
@@ -19,26 +19,28 @@
|
|
|
19
19
|
Module for mapping annotations into standard Detectron2 dataset dict. Also providing some tools for W&B mapping and
|
|
20
20
|
visualising
|
|
21
21
|
"""
|
|
22
|
-
|
|
22
|
+
from __future__ import annotations
|
|
23
23
|
|
|
24
24
|
import os.path
|
|
25
25
|
from typing import Dict, List, Mapping, Optional, Sequence, Tuple, Union
|
|
26
26
|
|
|
27
27
|
import numpy as np
|
|
28
|
-
import
|
|
28
|
+
from lazy_imports import try_import
|
|
29
29
|
|
|
30
30
|
from ..datapoint.annotation import ImageAnnotation
|
|
31
31
|
from ..datapoint.image import Image
|
|
32
32
|
from ..extern.pt.nms import batched_nms
|
|
33
33
|
from ..mapper.maputils import curry
|
|
34
34
|
from ..utils.detection_types import JsonDict
|
|
35
|
-
from ..utils.file_utils import detectron2_available, wandb_available
|
|
36
35
|
from ..utils.settings import ObjectTypes, TypeOrStr, get_type
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
with try_import() as pt_import_guard:
|
|
38
|
+
import torch
|
|
39
|
+
|
|
40
|
+
with try_import() as d2_import_guard:
|
|
39
41
|
from detectron2.structures import BoxMode
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
with try_import() as wb_import_guard:
|
|
42
44
|
from wandb import Classes
|
|
43
45
|
from wandb import Image as Wbimage
|
|
44
46
|
|
|
@@ -163,7 +165,7 @@ def to_wandb_image(
|
|
|
163
165
|
categories: Mapping[str, TypeOrStr],
|
|
164
166
|
sub_categories: Optional[Mapping[str, TypeOrStr]] = None,
|
|
165
167
|
cat_to_sub_cat: Optional[Mapping[ObjectTypes, ObjectTypes]] = None,
|
|
166
|
-
) -> Tuple[str,
|
|
168
|
+
) -> Tuple[str, Wbimage]:
|
|
167
169
|
"""
|
|
168
170
|
Converting a deepdoctection image into a wandb image
|
|
169
171
|
|
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
Module for mapping annotations into standard Huggingface Detr input structure for training
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
22
24
|
import os
|
|
23
25
|
from dataclasses import dataclass, field
|
|
24
26
|
from typing import Dict, List, Literal, Optional, Sequence, Union
|
|
25
27
|
|
|
26
28
|
import numpy as np
|
|
27
|
-
from
|
|
29
|
+
from lazy_imports import try_import
|
|
28
30
|
|
|
29
31
|
from ..datapoint.image import Image
|
|
30
32
|
from ..mapper.maputils import curry
|
|
@@ -33,6 +35,9 @@ from ..utils.detection_types import JsonDict
|
|
|
33
35
|
from ..utils.settings import ObjectTypes
|
|
34
36
|
from ..utils.transform import PadTransform
|
|
35
37
|
|
|
38
|
+
with try_import() as tr_import_guard:
|
|
39
|
+
from transformers import BatchFeature, DetrFeatureExtractor
|
|
40
|
+
|
|
36
41
|
|
|
37
42
|
@curry
|
|
38
43
|
def image_to_hf_detr_training(
|