Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HuggingFace Model Wrapper for Multi-Class Classification #3710

Merged

Conversation

harimkang
Copy link
Contributor

@harimkang harimkang commented Jul 4, 2024

Summary

  • Add HuggingFaceModelForMulticlassCls
  • Training, Testing, Exporting works

image
*The results of running the existing models are from workstation, and for the hugging face model, the results are from a different machine, so it is difficult to compare the time directly. Just a note.

Checked models

  • "nateraw/vit-base-beans", # Available
  • "google/vit-base-patch16-224", # Available
  • "google/mobilenet_v1_1.0_224", # Available
  • "google/efficientnet-b0", # Available
  • "microsoft/beit-base-patch16-224-pt22k-ft22k", # Available
  • "microsoft/swin-tiny-patch4-window7-224", # Available
  • "microsoft/resnet-18", # Available (but show NAN loss)
  • "facebook/convnextv2-tiny-1k-224", # Available
  • "facebook/dinov2-small-imagenet1k-1-layer", # Available
  • "facebook/deit-tiny-patch16-224", # Available

I haven't checked them all (too many models), but most of the models in the list below are available.
https://huggingface.co/models?pipeline_tag=image-classification

image

How to test

Install transformers
pip install transformers

API Examples

from otx.algo.classification.huggingface_model import HuggingFaceModelForMulticlassCls
from otx.engine import Engine

data_root = "/datasets/otx_v2_dataset/multiclass_classification/multiclass_food101_large"

otx_model = HuggingFaceModelForMulticlassCls(
    model_name_or_path="facebook/deit-tiny-patch16-224",
    label_info=20,
)

engine = Engine(
    data_root=data_root,
    model=otx_model,
    work_dir="otx-workspace-hf",
)

engine.train(max_epochs=2)
engine.test()
engine.export()
engine.test(checkpoint="otx-workspace-hf/exported_model.xml")

CLI Examples

(venv) ~/otx$ otx train \
    --model otx.algo.classification.huggingface_model.HuggingFaceModelForMulticlassCls \
    --model.model_name_or_path facebook/deit-tiny-patch16-224 \
    --data_root /datasets/otx_v2_dataset/multiclass_classification/multiclass_food101_large \
    --work_dir otx-workspace-hf-cli --max_epochs 3

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have ran e2e tests and there is no issues.
  • I have added the description of my changes into CHANGELOG in my target branch (e.g., CHANGELOG in develop).​
  • I have updated the documentation in my target branch accordingly (e.g., documentation in develop).
  • I have linked related issues.

License

  • I submit my code changes under the same Apache License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below).
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

@harimkang harimkang added this to the 2.2.0 milestone Jul 4, 2024
@github-actions github-actions bot added DEPENDENCY Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM TEST Any changes in tests BUILD labels Jul 8, 2024
@harimkang harimkang marked this pull request as ready for review July 8, 2024 05:20
Copy link
Contributor

@eunwoosh eunwoosh left a comment

Choose a reason for hiding this comment

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

Thanks for your work :) I left minor comment, Please take a look.

pyproject.toml Show resolved Hide resolved
@harimkang harimkang merged commit 96eb422 into openvinotoolkit:develop Jul 10, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUILD DEPENDENCY Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM TEST Any changes in tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants