qanastek / HugsVision

HugsVision is a easy to use huggingface wrapper for state-of-the-art computer vision
https://pypi.org/project/hugsvision/
MIT License
192 stars 21 forks source link

Using custom loss with VisionClassifierTrainer #40

Open guneetsk99 opened 2 years ago

guneetsk99 commented 2 years ago

I wanted to use a custom loss function with VIT how should I proceed since in the VisionClassifierTrainer there is no use of loss

qanastek commented 2 years ago

Hi,

Since the HugsVision VisionClassifierTrainer is based on the HuggingFace transformers library and especially on their Trainer, we cannot tweak the loss function.

image

guneetsk99 commented 2 years ago

Thanks @qanastek for the prompt response and its really an amazing library If possible can you suggest how I can use your models/ directory since there I can change the crossentropy loss to for eg KLDivLoss for testing

qanastek commented 2 years ago

HugsVision isn't really suited for reasearch. But you can directly rewrite the Transformers class ViTForImageClassification for the single_label_classification task.

In my opinion, it's the simplest way to do. Clone the Transformers repository, install it locally using pip install --editable . and modify the loss in the class.