__init__.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_flax_available,
  19. is_torch_available,
  20. )
  21. _import_structure = {"configuration_dinov2": ["Dinov2Config", "Dinov2OnnxConfig"]}
  22. try:
  23. if not is_torch_available():
  24. raise OptionalDependencyNotAvailable()
  25. except OptionalDependencyNotAvailable:
  26. pass
  27. else:
  28. _import_structure["modeling_dinov2"] = [
  29. "Dinov2ForImageClassification",
  30. "Dinov2Model",
  31. "Dinov2PreTrainedModel",
  32. "Dinov2Backbone",
  33. ]
  34. try:
  35. if not is_flax_available():
  36. raise OptionalDependencyNotAvailable()
  37. except OptionalDependencyNotAvailable:
  38. pass
  39. else:
  40. _import_structure["modeling_flax_dinov2"] = [
  41. "FlaxDinov2ForImageClassification",
  42. "FlaxDinov2Model",
  43. "FlaxDinov2PreTrainedModel",
  44. ]
  45. if TYPE_CHECKING:
  46. from .configuration_dinov2 import Dinov2Config, Dinov2OnnxConfig
  47. try:
  48. if not is_torch_available():
  49. raise OptionalDependencyNotAvailable()
  50. except OptionalDependencyNotAvailable:
  51. pass
  52. else:
  53. from .modeling_dinov2 import (
  54. Dinov2Backbone,
  55. Dinov2ForImageClassification,
  56. Dinov2Model,
  57. Dinov2PreTrainedModel,
  58. )
  59. try:
  60. if not is_flax_available():
  61. raise OptionalDependencyNotAvailable()
  62. except OptionalDependencyNotAvailable:
  63. pass
  64. else:
  65. from .modeling_flax_dinov2 import (
  66. FlaxDinov2ForImageClassification,
  67. FlaxDinov2Model,
  68. FlaxDinov2PreTrainedModel,
  69. )
  70. else:
  71. import sys
  72. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)