deepdoctection 0.30__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.

Files changed (120) hide show
  1. deepdoctection/__init__.py +38 -29
  2. deepdoctection/analyzer/dd.py +36 -29
  3. deepdoctection/configs/conf_dd_one.yaml +34 -31
  4. deepdoctection/dataflow/base.py +0 -19
  5. deepdoctection/dataflow/custom.py +4 -3
  6. deepdoctection/dataflow/custom_serialize.py +14 -5
  7. deepdoctection/dataflow/parallel_map.py +12 -11
  8. deepdoctection/dataflow/serialize.py +5 -4
  9. deepdoctection/datapoint/annotation.py +35 -13
  10. deepdoctection/datapoint/box.py +3 -5
  11. deepdoctection/datapoint/convert.py +3 -1
  12. deepdoctection/datapoint/image.py +79 -36
  13. deepdoctection/datapoint/view.py +152 -49
  14. deepdoctection/datasets/__init__.py +1 -4
  15. deepdoctection/datasets/adapter.py +6 -3
  16. deepdoctection/datasets/base.py +86 -11
  17. deepdoctection/datasets/dataflow_builder.py +1 -1
  18. deepdoctection/datasets/info.py +4 -4
  19. deepdoctection/datasets/instances/doclaynet.py +3 -2
  20. deepdoctection/datasets/instances/fintabnet.py +2 -1
  21. deepdoctection/datasets/instances/funsd.py +2 -1
  22. deepdoctection/datasets/instances/iiitar13k.py +5 -2
  23. deepdoctection/datasets/instances/layouttest.py +4 -8
  24. deepdoctection/datasets/instances/publaynet.py +2 -2
  25. deepdoctection/datasets/instances/pubtables1m.py +6 -3
  26. deepdoctection/datasets/instances/pubtabnet.py +2 -1
  27. deepdoctection/datasets/instances/rvlcdip.py +2 -1
  28. deepdoctection/datasets/instances/xfund.py +2 -1
  29. deepdoctection/eval/__init__.py +1 -4
  30. deepdoctection/eval/accmetric.py +1 -1
  31. deepdoctection/eval/base.py +5 -4
  32. deepdoctection/eval/cocometric.py +2 -1
  33. deepdoctection/eval/eval.py +19 -15
  34. deepdoctection/eval/tedsmetric.py +14 -11
  35. deepdoctection/eval/tp_eval_callback.py +14 -7
  36. deepdoctection/extern/__init__.py +2 -7
  37. deepdoctection/extern/base.py +39 -13
  38. deepdoctection/extern/d2detect.py +182 -90
  39. deepdoctection/extern/deskew.py +36 -9
  40. deepdoctection/extern/doctrocr.py +265 -83
  41. deepdoctection/extern/fastlang.py +49 -9
  42. deepdoctection/extern/hfdetr.py +106 -55
  43. deepdoctection/extern/hflayoutlm.py +441 -122
  44. deepdoctection/extern/hflm.py +225 -0
  45. deepdoctection/extern/model.py +56 -47
  46. deepdoctection/extern/pdftext.py +10 -5
  47. deepdoctection/extern/pt/__init__.py +1 -3
  48. deepdoctection/extern/pt/nms.py +6 -2
  49. deepdoctection/extern/pt/ptutils.py +27 -18
  50. deepdoctection/extern/tessocr.py +134 -22
  51. deepdoctection/extern/texocr.py +6 -2
  52. deepdoctection/extern/tp/tfutils.py +43 -9
  53. deepdoctection/extern/tp/tpcompat.py +14 -11
  54. deepdoctection/extern/tp/tpfrcnn/__init__.py +20 -0
  55. deepdoctection/extern/tp/tpfrcnn/common.py +7 -3
  56. deepdoctection/extern/tp/tpfrcnn/config/__init__.py +20 -0
  57. deepdoctection/extern/tp/tpfrcnn/config/config.py +9 -6
  58. deepdoctection/extern/tp/tpfrcnn/modeling/__init__.py +20 -0
  59. deepdoctection/extern/tp/tpfrcnn/modeling/backbone.py +17 -7
  60. deepdoctection/extern/tp/tpfrcnn/modeling/generalized_rcnn.py +12 -6
  61. deepdoctection/extern/tp/tpfrcnn/modeling/model_box.py +9 -4
  62. deepdoctection/extern/tp/tpfrcnn/modeling/model_cascade.py +8 -5
  63. deepdoctection/extern/tp/tpfrcnn/modeling/model_fpn.py +16 -11
  64. deepdoctection/extern/tp/tpfrcnn/modeling/model_frcnn.py +17 -10
  65. deepdoctection/extern/tp/tpfrcnn/modeling/model_mrcnn.py +14 -8
  66. deepdoctection/extern/tp/tpfrcnn/modeling/model_rpn.py +15 -10
  67. deepdoctection/extern/tp/tpfrcnn/predict.py +9 -4
  68. deepdoctection/extern/tp/tpfrcnn/preproc.py +8 -9
  69. deepdoctection/extern/tp/tpfrcnn/utils/__init__.py +20 -0
  70. deepdoctection/extern/tp/tpfrcnn/utils/box_ops.py +10 -2
  71. deepdoctection/extern/tpdetect.py +54 -30
  72. deepdoctection/mapper/__init__.py +3 -8
  73. deepdoctection/mapper/d2struct.py +9 -7
  74. deepdoctection/mapper/hfstruct.py +7 -2
  75. deepdoctection/mapper/laylmstruct.py +164 -21
  76. deepdoctection/mapper/maputils.py +16 -3
  77. deepdoctection/mapper/misc.py +6 -3
  78. deepdoctection/mapper/prodigystruct.py +1 -1
  79. deepdoctection/mapper/pubstruct.py +10 -10
  80. deepdoctection/mapper/tpstruct.py +3 -3
  81. deepdoctection/pipe/__init__.py +1 -1
  82. deepdoctection/pipe/anngen.py +35 -8
  83. deepdoctection/pipe/base.py +53 -19
  84. deepdoctection/pipe/common.py +23 -13
  85. deepdoctection/pipe/concurrency.py +2 -1
  86. deepdoctection/pipe/doctectionpipe.py +2 -2
  87. deepdoctection/pipe/language.py +3 -2
  88. deepdoctection/pipe/layout.py +6 -3
  89. deepdoctection/pipe/lm.py +34 -66
  90. deepdoctection/pipe/order.py +142 -35
  91. deepdoctection/pipe/refine.py +26 -24
  92. deepdoctection/pipe/segment.py +21 -16
  93. deepdoctection/pipe/{cell.py → sub_layout.py} +30 -9
  94. deepdoctection/pipe/text.py +14 -8
  95. deepdoctection/pipe/transform.py +16 -9
  96. deepdoctection/train/__init__.py +6 -12
  97. deepdoctection/train/d2_frcnn_train.py +36 -28
  98. deepdoctection/train/hf_detr_train.py +26 -17
  99. deepdoctection/train/hf_layoutlm_train.py +133 -111
  100. deepdoctection/train/tp_frcnn_train.py +21 -19
  101. deepdoctection/utils/__init__.py +3 -0
  102. deepdoctection/utils/concurrency.py +1 -1
  103. deepdoctection/utils/context.py +2 -2
  104. deepdoctection/utils/env_info.py +41 -84
  105. deepdoctection/utils/error.py +84 -0
  106. deepdoctection/utils/file_utils.py +4 -15
  107. deepdoctection/utils/fs.py +7 -7
  108. deepdoctection/utils/logger.py +1 -0
  109. deepdoctection/utils/mocks.py +93 -0
  110. deepdoctection/utils/pdf_utils.py +5 -4
  111. deepdoctection/utils/settings.py +6 -1
  112. deepdoctection/utils/transform.py +1 -1
  113. deepdoctection/utils/utils.py +0 -6
  114. deepdoctection/utils/viz.py +48 -5
  115. {deepdoctection-0.30.dist-info → deepdoctection-0.32.dist-info}/METADATA +57 -73
  116. deepdoctection-0.32.dist-info/RECORD +146 -0
  117. {deepdoctection-0.30.dist-info → deepdoctection-0.32.dist-info}/WHEEL +1 -1
  118. deepdoctection-0.30.dist-info/RECORD +0 -143
  119. {deepdoctection-0.30.dist-info → deepdoctection-0.32.dist-info}/LICENSE +0 -0
  120. {deepdoctection-0.30.dist-info → deepdoctection-0.32.dist-info}/top_level.txt +0 -0
@@ -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
- # pylint: enable=import-error
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
- # pylint: disable=import-error
12
- import tensorflow as tf
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
- # pylint: enable=import-error
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
- # pylint: disable=import-error
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
- # pylint: enable=import-error
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
- # pylint: enable=import-error
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 tensorpack.predict.base import OfflinePredictor # pylint: disable=E0401
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
- if scipy_available():
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,29 +8,28 @@
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
20
+ from ....utils.error import MalformedData
21
21
  from ....utils.logger import log_once
22
22
  from .common import filter_boxes_inside_shape, np_iou
23
23
  from .modeling.model_fpn import get_all_anchors_fpn
24
24
  from .utils.np_box_ops import area as np_area
25
25
  from .utils.np_box_ops import ioa as np_ioa
26
26
 
27
- # pylint: enable=import-error
27
+ # pylint: disable=import-error
28
28
 
29
29
 
30
- class MalformedData(BaseException):
31
- """
32
- Exception class for malformed data
33
- """
30
+ with try_import() as import_guard:
31
+ from tensorpack.dataflow.imgaug import AugmentorList, ImageAugmentor
32
+ # pylint: enable=import-error
34
33
 
35
34
 
36
35
  def augment(dp: JsonDict, imgaug_list: List[ImageAugmentor], add_mask: bool) -> JsonDict:
@@ -62,7 +61,7 @@ def augment(dp: JsonDict, imgaug_list: List[ImageAugmentor], add_mask: bool) ->
62
61
  assert np.min(np_area(gt_boxes)) > 0, "some boxes have zero area"
63
62
 
64
63
  if add_mask:
65
- raise NotImplementedError
64
+ raise NotImplementedError()
66
65
 
67
66
  return dp
68
67
 
@@ -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
- import tensorflow as tf
19
- from tensorpack.tfutils.scope_utils import under_name_scope
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
 
@@ -19,24 +19,62 @@
19
19
  TP Faster RCNN model as predictor for deepdoctection pipeline
20
20
  """
21
21
 
22
+ from abc import ABC
22
23
  from copy import copy
23
24
  from pathlib import Path
24
- from typing import List, Mapping, Optional, Sequence, Union
25
+ from typing import Dict, List, Mapping, Optional, Sequence, Union
25
26
 
26
27
  from ..utils.detection_types import ImageType, Requirement
27
- from ..utils.file_utils import get_tensorflow_requirement, get_tensorpack_requirement, tensorpack_available
28
+ from ..utils.file_utils import get_tensorflow_requirement, get_tensorpack_requirement
28
29
  from ..utils.metacfg import set_config_by_yaml
29
30
  from ..utils.settings import ObjectTypes, TypeOrStr, get_type
30
31
  from .base import DetectionResult, ObjectDetector, PredictorBase
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
31
36
 
32
- if tensorpack_available():
33
- from .tp.tpcompat import TensorpackPredictor
34
- from .tp.tpfrcnn.config.config import model_frcnn_config
35
- from .tp.tpfrcnn.modeling.generalized_rcnn import ResNetFPNModel
36
- from .tp.tpfrcnn.predict import tp_predict_image
37
37
 
38
+ class TPFrcnnDetectorMixin(ObjectDetector, ABC):
39
+ """Base class for TP FRCNN detector. This class only implements the basic wrapper functions"""
38
40
 
39
- class TPFrcnnDetector(TensorpackPredictor, ObjectDetector):
41
+ def __init__(self, categories: Mapping[str, TypeOrStr], filter_categories: Optional[Sequence[TypeOrStr]] = None):
42
+ self.categories = copy(categories) # type: ignore
43
+ if filter_categories:
44
+ filter_categories = [get_type(cat) for cat in filter_categories]
45
+ self.filter_categories = filter_categories
46
+ self._tp_categories = self._map_to_tp_categories(categories)
47
+
48
+ def _map_category_names(self, detection_results: List[DetectionResult]) -> List[DetectionResult]:
49
+ """
50
+ Populating category names to detection results
51
+
52
+ :param detection_results: list of detection results
53
+ :return: List of detection results with attribute class_name populated
54
+ """
55
+ filtered_detection_result: List[DetectionResult] = []
56
+ for result in detection_results:
57
+ result.class_name = self._tp_categories[str(result.class_id)]
58
+ if self.filter_categories:
59
+ if result.class_name not in self.filter_categories:
60
+ filtered_detection_result.append(result)
61
+ else:
62
+ filtered_detection_result.append(result)
63
+ return filtered_detection_result
64
+
65
+ @staticmethod
66
+ def _map_to_tp_categories(categories: Mapping[str, TypeOrStr]) -> Dict[str, ObjectTypes]:
67
+ categories = {str(key): get_type(categories[val]) for key, val in enumerate(categories, 1)}
68
+ categories["0"] = get_type("background")
69
+ return categories # type: ignore
70
+
71
+ @staticmethod
72
+ def get_name(path_weights: str, architecture: str) -> str:
73
+ """Returns the name of the model"""
74
+ return f"Tensorpack_{architecture}" + "_".join(Path(path_weights).parts[-2:])
75
+
76
+
77
+ class TPFrcnnDetector(TensorpackPredictor, TPFrcnnDetectorMixin):
40
78
  """
41
79
  Tensorpack Faster-RCNN implementation with FPN and optional Cascade-RCNN. The backbones Resnet-50, Resnet-101 and
42
80
  their Resnext counterparts are also available. Normalization options (group normalization, synchronized batch
@@ -87,19 +125,22 @@ class TPFrcnnDetector(TensorpackPredictor, ObjectDetector):
87
125
  :param filter_categories: The model might return objects that are not supposed to be predicted and that should
88
126
  be filtered. Pass a list of category names that must not be returned
89
127
  """
90
- self.name = "_".join(Path(path_weights).parts[-3:])
91
128
  self.path_yaml = path_yaml
129
+
92
130
  self.categories = copy(categories) # type: ignore
93
131
  self.config_overwrite = config_overwrite
94
132
  if filter_categories:
95
133
  filter_categories = [get_type(cat) for cat in filter_categories]
96
134
  self.filter_categories = filter_categories
97
- model = TPFrcnnDetector.set_model(path_yaml, self.categories, config_overwrite)
98
- super().__init__(model, path_weights, ignore_mismatch)
99
- assert self._number_gpus > 0, "Model only support inference with GPU"
135
+ model = TPFrcnnDetector.get_wrapped_model(path_yaml, self.categories, config_overwrite)
136
+ TensorpackPredictor.__init__(self, model, path_weights, ignore_mismatch)
137
+ TPFrcnnDetectorMixin.__init__(self, categories, filter_categories)
138
+
139
+ self.name = self.get_name(path_weights, self._model.cfg.TAG)
140
+ self.model_id = self.get_model_id()
100
141
 
101
142
  @staticmethod
102
- def set_model(
143
+ def get_wrapped_model(
103
144
  path_yaml: str, categories: Mapping[str, ObjectTypes], config_overwrite: Union[List[str], None]
104
145
  ) -> ResNetFPNModel:
105
146
  """
@@ -138,23 +179,6 @@ class TPFrcnnDetector(TensorpackPredictor, ObjectDetector):
138
179
  )
139
180
  return self._map_category_names(detection_results)
140
181
 
141
- def _map_category_names(self, detection_results: List[DetectionResult]) -> List[DetectionResult]:
142
- """
143
- Populating category names to detection results
144
-
145
- :param detection_results: list of detection results
146
- :return: List of detection results with attribute class_name populated
147
- """
148
- filtered_detection_result: List[DetectionResult] = []
149
- for result in detection_results:
150
- result.class_name = self._model.cfg.DATA.CLASS_DICT[str(result.class_id)]
151
- if self.filter_categories:
152
- if result.class_name not in self.filter_categories:
153
- filtered_detection_result.append(result)
154
- else:
155
- filtered_detection_result.append(result)
156
- return filtered_detection_result
157
-
158
182
  @classmethod
159
183
  def get_requirements(cls) -> List[Requirement]:
160
184
  return [get_tensorflow_requirement(), get_tensorpack_requirement()]
@@ -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 torch
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
- if detectron2_available():
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
- if wandb_available():
43
+ with try_import() as wb_import_guard:
42
44
  from wandb import Classes
43
45
  from wandb import Image as Wbimage
44
46
 
@@ -93,7 +95,7 @@ def image_to_d2_frcnn_training(
93
95
  annotations.append(mapped_ann)
94
96
 
95
97
  if add_mask:
96
- raise NotImplementedError
98
+ raise NotImplementedError("Segmentation in deepdoctection is not supported")
97
99
 
98
100
  output["annotations"] = annotations
99
101
 
@@ -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, "Wbimage"]:
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 transformers import BatchFeature, DetrFeatureExtractor
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(
@@ -81,7 +86,7 @@ def image_to_hf_detr_training(
81
86
  annotations.append(mapped_ann)
82
87
 
83
88
  if add_mask:
84
- raise NotImplementedError
89
+ raise NotImplementedError("Segmentation in deepdoctection is not supported")
85
90
 
86
91
  output["annotations"] = annotations
87
92