__init__.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright 2023 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_tf_available,
  19. is_torch_available,
  20. is_vision_available,
  21. )
  22. _import_structure = {
  23. "configuration_sam": [
  24. "SamConfig",
  25. "SamMaskDecoderConfig",
  26. "SamPromptEncoderConfig",
  27. "SamVisionConfig",
  28. ],
  29. "processing_sam": ["SamProcessor"],
  30. }
  31. try:
  32. if not is_torch_available():
  33. raise OptionalDependencyNotAvailable()
  34. except OptionalDependencyNotAvailable:
  35. pass
  36. else:
  37. _import_structure["modeling_sam"] = [
  38. "SamModel",
  39. "SamPreTrainedModel",
  40. ]
  41. try:
  42. if not is_tf_available():
  43. raise OptionalDependencyNotAvailable()
  44. except OptionalDependencyNotAvailable:
  45. pass
  46. else:
  47. _import_structure["modeling_tf_sam"] = [
  48. "TFSamModel",
  49. "TFSamPreTrainedModel",
  50. ]
  51. try:
  52. if not is_vision_available():
  53. raise OptionalDependencyNotAvailable()
  54. except OptionalDependencyNotAvailable:
  55. pass
  56. else:
  57. _import_structure["image_processing_sam"] = ["SamImageProcessor"]
  58. if TYPE_CHECKING:
  59. from .configuration_sam import (
  60. SamConfig,
  61. SamMaskDecoderConfig,
  62. SamPromptEncoderConfig,
  63. SamVisionConfig,
  64. )
  65. from .processing_sam import SamProcessor
  66. try:
  67. if not is_torch_available():
  68. raise OptionalDependencyNotAvailable()
  69. except OptionalDependencyNotAvailable:
  70. pass
  71. else:
  72. from .modeling_sam import SamModel, SamPreTrainedModel
  73. try:
  74. if not is_tf_available():
  75. raise OptionalDependencyNotAvailable()
  76. except OptionalDependencyNotAvailable:
  77. pass
  78. else:
  79. from .modeling_tf_sam import TFSamModel, TFSamPreTrainedModel
  80. try:
  81. if not is_vision_available():
  82. raise OptionalDependencyNotAvailable()
  83. except OptionalDependencyNotAvailable:
  84. pass
  85. else:
  86. from .image_processing_sam import SamImageProcessor
  87. else:
  88. import sys
  89. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)