Add ImageFeatureExtractionMixin (#10905)
* Add ImageFeatureExtractionMixin * Add dummy vision objects * Add require_vision * Add tests * Fix test
This commit is contained in:
@@ -39,6 +39,7 @@ from .file_utils import (
|
||||
is_torch_available,
|
||||
is_torch_tpu_available,
|
||||
is_torchaudio_available,
|
||||
is_vision_available,
|
||||
)
|
||||
from .integrations import is_optuna_available, is_ray_available
|
||||
|
||||
@@ -229,12 +230,9 @@ def require_torch_scatter(test_case):
|
||||
|
||||
def require_torchaudio(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires torchaudio.
|
||||
|
||||
These tests are skipped when torchaudio isn't installed.
|
||||
|
||||
Decorator marking a test that requires torchaudio. These tests are skipped when torchaudio isn't installed.
|
||||
"""
|
||||
if not is_torchaudio_available:
|
||||
if not is_torchaudio_available():
|
||||
return unittest.skip("test requires torchaudio")(test_case)
|
||||
else:
|
||||
return test_case
|
||||
@@ -242,10 +240,7 @@ def require_torchaudio(test_case):
|
||||
|
||||
def require_tf(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires TensorFlow.
|
||||
|
||||
These tests are skipped when TensorFlow isn't installed.
|
||||
|
||||
Decorator marking a test that requires TensorFlow. These tests are skipped when TensorFlow isn't installed.
|
||||
"""
|
||||
if not is_tf_available():
|
||||
return unittest.skip("test requires TensorFlow")(test_case)
|
||||
@@ -255,10 +250,7 @@ def require_tf(test_case):
|
||||
|
||||
def require_flax(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires JAX & Flax
|
||||
|
||||
These tests are skipped when one / both are not installed
|
||||
|
||||
Decorator marking a test that requires JAX & Flax. These tests are skipped when one / both are not installed
|
||||
"""
|
||||
if not is_flax_available():
|
||||
test_case = unittest.skip("test requires JAX & Flax")(test_case)
|
||||
@@ -267,10 +259,7 @@ def require_flax(test_case):
|
||||
|
||||
def require_sentencepiece(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires SentencePiece.
|
||||
|
||||
These tests are skipped when SentencePiece isn't installed.
|
||||
|
||||
Decorator marking a test that requires SentencePiece. These tests are skipped when SentencePiece isn't installed.
|
||||
"""
|
||||
if not is_sentencepiece_available():
|
||||
return unittest.skip("test requires SentencePiece")(test_case)
|
||||
@@ -280,10 +269,7 @@ def require_sentencepiece(test_case):
|
||||
|
||||
def require_tokenizers(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires 🤗 Tokenizers.
|
||||
|
||||
These tests are skipped when 🤗 Tokenizers isn't installed.
|
||||
|
||||
Decorator marking a test that requires 🤗 Tokenizers. These tests are skipped when 🤗 Tokenizers isn't installed.
|
||||
"""
|
||||
if not is_tokenizers_available():
|
||||
return unittest.skip("test requires tokenizers")(test_case)
|
||||
@@ -312,11 +298,21 @@ def require_scatter(test_case):
|
||||
return test_case
|
||||
|
||||
|
||||
def require_vision(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires the vision dependencies. These tests are skipped when torchaudio isn't
|
||||
installed.
|
||||
"""
|
||||
if not is_vision_available():
|
||||
return unittest.skip("test requires vision")(test_case)
|
||||
else:
|
||||
return test_case
|
||||
|
||||
|
||||
def require_torch_multi_gpu(test_case):
|
||||
"""
|
||||
Decorator marking a test that requires a multi-GPU setup (in PyTorch).
|
||||
|
||||
These tests are skipped on a machine without multiple GPUs.
|
||||
Decorator marking a test that requires a multi-GPU setup (in PyTorch). These tests are skipped on a machine without
|
||||
multiple GPUs.
|
||||
|
||||
To run *only* the multi_gpu tests, assuming all test names contain multi_gpu: $ pytest -sv ./tests -k "multi_gpu"
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user