-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Description
System Info
transformersversion: 4.25.1- Platform: macOS-11.6.8-x86_64-i386-64bit
- Python version: 3.10.8
- Huggingface_hub version: 0.11.1
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no
Who can help?
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - My own task or dataset (give details below)
Reproduction
Steps to reproduce the behavior:
- Create and activate clean Python environment
python3 -m venv venv source venv/bin/activate - Install
transformersand its direct dependenciespip install transformers
- Attempt to import
transformers.image_transformsor one of its publicly-documented memberspython -c 'from transformers.image_transforms import center_crop' - Encounter a
NameErrorNone of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used. Traceback (most recent call last): File "<string>", line 1, in <module> File "/Users/miliu/venv/lib/python3.10/site-packages/transformers/image_transforms.py", line 51, in <module> def to_channel_dimension_format(image: np.ndarray, channel_dim: Union[ChannelDimension, str]) -> np.ndarray: NameError: name 'ChannelDimension' is not defined
Expected behavior
Rather than a NameError on import (caused by to_channel_dimension_format()'s signature type annotation containing ChannelDimension, which is conditionally imported only when PIL is available), I would've expected something like transformers.rescale's user experience, where it helpfully recommends installing Pillow when one attempts to use it:
>>> from transformers import rescale
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
>>> rescale()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/miliu/venv/lib/python3.10/site-packages/transformers/utils/dummy_vision_objects.py", line 14, in rescale
requires_backends(rescale, ["vision"])
File "/Users/miliu/venv/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 997, in requires_backends
raise ImportError("".join(failed))
ImportError:
rescale requires the PIL library but it was not found in your environment. You can install it with pip:
`pip install pillow`. Please note that you may need to restart your runtime after installation.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels