1

I am unable to plot the validation accuracies Vs epoch curve while using the following code

from hugsvision.nnet.VisionClassifierTrainer import VisionClassifierTrainer
from transformers import ViTFeatureExtractor, ViTForImageClassification

`trainer = VisionClassifierTrainer(
    model_name   = "MyKvasirV2Model11",
    train        = train,
    test         = test,
    output_dir   = "/content/drive/MyDrive/Untitled Folder",
    #max_epochs   = 10,
    #batch_size   = 32, # On RTX 2080 Ti
        #   lr           = 2e-5,

    max_epochs   = 2,
    batch_size   = 50, # On RTX 2080 Ti
        lr           = 2e-5,
    # fp16       = True,
    model = ViTForImageClassification.from_pretrained(
        huggingface_model,
        num_labels = len(label2id),
        label2id   = label2id,
        id2label   = id2label
    ),
    feature_extractor = ViTFeatureExtractor.from_pretrained(
        huggingface_model,
    ),
)

I am trying a binary image classification and not getting the validation accuracies per epoch

Anu Raj
  • 11
  • 1

1 Answers1

1

You can get the validation accuracies per epoch by using the log_history=True parameter when creating the VisionClassifierTrainer object, which will return the history of training metrics, including validation accuracy, after training is completed.

Mehdi sahraei
  • 173
  • 2
  • 10
  • Hi, Thanks for your timely response. – Anu Raj May 08 '23 at 18:12
  • But still, I am not getting validation accuracies. I got the following error VisionClassifierTrainer.__init__() got an unexpected keyword argument 'log_history' – Anu Raj May 08 '23 at 18:14
  • Can you suggest me another method to print the validation accuracies per epoch for VisionClassifierTrainer – Anu Raj May 09 '23 at 01:43
  • create a custom callback function: import torch from pytorch_lightning.callbacks import Callback class ValidationAccuracyCallback(Callback): def on_validation_end(self, trainer, pl_module): val_acc = trainer.callback_metrics['val_acc'] print(f"Validation accuracy: {val_acc:.4f}") – Mehdi sahraei May 10 '23 at 07:29