__init__.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_flax_available,
  19. is_tf_available,
  20. is_torch_available,
  21. is_torchvision_available,
  22. is_vision_available,
  23. )
  24. _import_structure = {"configuration_vit": ["ViTConfig", "ViTOnnxConfig"]}
  25. try:
  26. if not is_vision_available():
  27. raise OptionalDependencyNotAvailable()
  28. except OptionalDependencyNotAvailable:
  29. pass
  30. else:
  31. _import_structure["feature_extraction_vit"] = ["ViTFeatureExtractor"]
  32. _import_structure["image_processing_vit"] = ["ViTImageProcessor"]
  33. try:
  34. if not is_torchvision_available():
  35. raise OptionalDependencyNotAvailable()
  36. except OptionalDependencyNotAvailable:
  37. pass
  38. else:
  39. _import_structure["image_processing_vit_fast"] = ["ViTImageProcessorFast"]
  40. try:
  41. if not is_torch_available():
  42. raise OptionalDependencyNotAvailable()
  43. except OptionalDependencyNotAvailable:
  44. pass
  45. else:
  46. _import_structure["modeling_vit"] = [
  47. "ViTForImageClassification",
  48. "ViTForMaskedImageModeling",
  49. "ViTModel",
  50. "ViTPreTrainedModel",
  51. ]
  52. try:
  53. if not is_tf_available():
  54. raise OptionalDependencyNotAvailable()
  55. except OptionalDependencyNotAvailable:
  56. pass
  57. else:
  58. _import_structure["modeling_tf_vit"] = [
  59. "TFViTForImageClassification",
  60. "TFViTModel",
  61. "TFViTPreTrainedModel",
  62. ]
  63. try:
  64. if not is_flax_available():
  65. raise OptionalDependencyNotAvailable()
  66. except OptionalDependencyNotAvailable:
  67. pass
  68. else:
  69. _import_structure["modeling_flax_vit"] = [
  70. "FlaxViTForImageClassification",
  71. "FlaxViTModel",
  72. "FlaxViTPreTrainedModel",
  73. ]
  74. if TYPE_CHECKING:
  75. from .configuration_vit import ViTConfig, ViTOnnxConfig
  76. try:
  77. if not is_vision_available():
  78. raise OptionalDependencyNotAvailable()
  79. except OptionalDependencyNotAvailable:
  80. pass
  81. else:
  82. from .feature_extraction_vit import ViTFeatureExtractor
  83. from .image_processing_vit import ViTImageProcessor
  84. try:
  85. if not is_torchvision_available():
  86. raise OptionalDependencyNotAvailable()
  87. except OptionalDependencyNotAvailable:
  88. pass
  89. else:
  90. from .image_processing_vit_fast import ViTImageProcessorFast
  91. try:
  92. if not is_torch_available():
  93. raise OptionalDependencyNotAvailable()
  94. except OptionalDependencyNotAvailable:
  95. pass
  96. else:
  97. from .modeling_vit import (
  98. ViTForImageClassification,
  99. ViTForMaskedImageModeling,
  100. ViTModel,
  101. ViTPreTrainedModel,
  102. )
  103. try:
  104. if not is_tf_available():
  105. raise OptionalDependencyNotAvailable()
  106. except OptionalDependencyNotAvailable:
  107. pass
  108. else:
  109. from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel
  110. try:
  111. if not is_flax_available():
  112. raise OptionalDependencyNotAvailable()
  113. except OptionalDependencyNotAvailable:
  114. pass
  115. else:
  116. from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel
  117. else:
  118. import sys
  119. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)