__init__.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Copyright 2021 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import TYPE_CHECKING
  15. from ...utils import (
  16. OptionalDependencyNotAvailable,
  17. _LazyModule,
  18. is_tokenizers_available,
  19. is_torch_available,
  20. is_vision_available,
  21. )
  22. _import_structure = {
  23. "configuration_layoutlmv2": ["LayoutLMv2Config"],
  24. "processing_layoutlmv2": ["LayoutLMv2Processor"],
  25. "tokenization_layoutlmv2": ["LayoutLMv2Tokenizer"],
  26. }
  27. try:
  28. if not is_tokenizers_available():
  29. raise OptionalDependencyNotAvailable()
  30. except OptionalDependencyNotAvailable:
  31. pass
  32. else:
  33. _import_structure["tokenization_layoutlmv2_fast"] = ["LayoutLMv2TokenizerFast"]
  34. try:
  35. if not is_vision_available():
  36. raise OptionalDependencyNotAvailable()
  37. except OptionalDependencyNotAvailable:
  38. pass
  39. else:
  40. _import_structure["feature_extraction_layoutlmv2"] = ["LayoutLMv2FeatureExtractor"]
  41. _import_structure["image_processing_layoutlmv2"] = ["LayoutLMv2ImageProcessor"]
  42. try:
  43. if not is_torch_available():
  44. raise OptionalDependencyNotAvailable()
  45. except OptionalDependencyNotAvailable:
  46. pass
  47. else:
  48. _import_structure["modeling_layoutlmv2"] = [
  49. "LayoutLMv2ForQuestionAnswering",
  50. "LayoutLMv2ForSequenceClassification",
  51. "LayoutLMv2ForTokenClassification",
  52. "LayoutLMv2Layer",
  53. "LayoutLMv2Model",
  54. "LayoutLMv2PreTrainedModel",
  55. ]
  56. if TYPE_CHECKING:
  57. from .configuration_layoutlmv2 import LayoutLMv2Config
  58. from .processing_layoutlmv2 import LayoutLMv2Processor
  59. from .tokenization_layoutlmv2 import LayoutLMv2Tokenizer
  60. try:
  61. if not is_tokenizers_available():
  62. raise OptionalDependencyNotAvailable()
  63. except OptionalDependencyNotAvailable:
  64. pass
  65. else:
  66. from .tokenization_layoutlmv2_fast import LayoutLMv2TokenizerFast
  67. try:
  68. if not is_vision_available():
  69. raise OptionalDependencyNotAvailable()
  70. except OptionalDependencyNotAvailable:
  71. pass
  72. else:
  73. from .feature_extraction_layoutlmv2 import LayoutLMv2FeatureExtractor, LayoutLMv2ImageProcessor
  74. try:
  75. if not is_torch_available():
  76. raise OptionalDependencyNotAvailable()
  77. except OptionalDependencyNotAvailable:
  78. pass
  79. else:
  80. from .modeling_layoutlmv2 import (
  81. LayoutLMv2ForQuestionAnswering,
  82. LayoutLMv2ForSequenceClassification,
  83. LayoutLMv2ForTokenClassification,
  84. LayoutLMv2Layer,
  85. LayoutLMv2Model,
  86. LayoutLMv2PreTrainedModel,
  87. )
  88. else:
  89. import sys
  90. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)