Skip to content

Added scikit-learn to the example image-classification requirements.txt#37506

Merged
ArthurZucker merged 4 commits into
huggingface:mainfrom
mylonjones:add-scikit-learn-to-pytorch-example-image-classification
Jun 24, 2025
Merged

Added scikit-learn to the example image-classification requirements.txt#37506
ArthurZucker merged 4 commits into
huggingface:mainfrom
mylonjones:add-scikit-learn-to-pytorch-example-image-classification

Conversation

@mylonjones

@mylonjones mylonjones commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

Fix dependency in examples/pytorch/image-classification/requirements.txt

I ran into an error when trying to run the image-classification example with the following program
transformers\examples\pytorch\image-classification\run_image_classification.py

First I ran pip install -r requirements.txt and tried to run the program using the example in the README.md

python run_image_classification.py --dataset_name beans --output_dir ./beans_outputs/ --remove_unused_columns False --label_column_name labels --do_train --do_eval --push_to_hub --push_to_hub_model_id vit-base-beans --learning_rate 2e-5 --num_train_epochs 5 --per_device_train_batch_size 8 --per_device_eval_batch_size 8 --logging_strategy steps --logging_steps 10 --eval_strategy epoch --save_strategy epoch --load_best_model_at_end True --save_total_limit 3 --seed 1337

Then I got this error.

Traceback (most recent call last):
  File "C:\Users\mylon\transformers\examples\pytorch\image-classification\run_image_classification.py", line 441, in <module>
    main()
    ~~~~^^
  File "C:\Users\mylon\transformers\examples\pytorch\image-classification\run_image_classification.py", line 294, in main       
    metric = evaluate.load("accuracy", cache_dir=model_args.cache_dir)
  File "C:\Users\mylon\.venv\Lib\site-packages\evaluate\loading.py", line 751, in load
    evaluation_cls = import_main_class(evaluation_module.module_path)
  File "C:\Users\mylon\.venv\Lib\site-packages\evaluate\loading.py", line 76, in import_main_class
    module = importlib.import_module(module_path)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1008.0_x64__qbz5n2kfra8p0\Lib\importlib\__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\mylon\.cache\huggingface\modules\evaluate_modules\metrics\evaluate-metric--accuracy\f887c0aab52c2d38e1f8a215681126379eca617f96c447638f751434e8e65b14\accuracy.py", line 17, in <module>
    from sklearn.metrics import accuracy_score
ModuleNotFoundError: No module named 'sklearn'

So I ran pip install sklearn and got this error.

Collecting sklearn
  Using cached sklearn-0.0.post12.tar.gz (2.6 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [15 lines of output]
      The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
      rather than 'sklearn' for pip commands.
     
      Here is how to fix this error in the main use cases:
      - use 'pip install scikit-learn' rather than 'pip install sklearn'
      - replace 'sklearn' by 'scikit-learn' in your pip requirements files
        (requirements.txt, setup.py, setup.cfg, Pipfile, etc ...)
      - if the 'sklearn' package is used by one of your dependencies,
        it would be great if you take some time to track which package uses
        'sklearn' instead of 'scikit-learn' and report it to their issue tracker
      - as a last resort, set the environment variable
        SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True to avoid this error
     
      More information is available at
      https://github.com/scikit-learn/sklearn-pypi-package
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

So finally I added scikit-learn to the requirements.txt file and installed it and now the program works just fine.

Here are my system details.

  • transformers version: 4.52.0.dev0
  • Platform: Windows-10-10.0.19045-SP0
  • Python version: 3.13.3
  • Huggingface_hub version: 0.30.2
  • Safetensors version: 0.5.3
  • Accelerate version: 1.6.0
  • Accelerate config: not found
  • DeepSpeed version: not installed
  • PyTorch version (GPU?): 2.6.0+cpu (False)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using distributed or parallel set-up in script?: NO

I would like to make this contribution because I think it would people some time when trying out this example program.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions github-actions Bot marked this pull request as draft April 14, 2025 22:49
@github-actions

Copy link
Copy Markdown
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@mylonjones

Copy link
Copy Markdown
Contributor Author

@amyeroberts, @qubvel

@mylonjones mylonjones marked this pull request as ready for review April 14, 2025 22:51

@qubvel qubvel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ArthurZucker ArthurZucker merged commit 9f42c1f into huggingface:main Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants