File size: 3,547 Bytes
50224a7 4e80ea4 50224a7 4e80ea4 50224a7 1d7cf1c 50224a7 4e80ea4 50224a7 4e80ea4 50224a7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
---
library_name: peft
license: gemma
base_model: google/paligemma-3b-pt-224
tags:
- generated_from_trainer
datasets:
- imagefolder
- FastJobs/Visual_Emotional_Analysis
model-index:
- name: emotion_classification
results: []
---
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->
# emotion_classification
This model is a fine-tuned version of [google/paligemma-3b-pt-224](https://huggingface.co/google/paligemma-3b-pt-224) on the [FastJobs/Visual_Emotional_Analysis](https://huggingface.co/datasets/FastJobs/Visual_Emotional_Analysis) dataset.
## Training Data
This model was trained on the [FastJobs/Visual_Emotional_Analysis](https://huggingface.co/datasets/FastJobs/Visual_Emotional_Analysis) dataset.
The dataset contains:
- **800 images** annotated with **8 emotion labels**:
- Anger
- Contempt
- Disgust
- Fear
- Happy
- Neutral
- Sad
- Surprise
## Intended uses & limitations
### Intended Uses
- Emotion classification from visual inputs (images).
### Limitations
- May reflect biases from the training dataset.
- Performance may degrade in domains outside the training data.
- Not suitable for critical or sensitive decision-making tasks.
## How to use this model
```python
from transformers import (PaliGemmaProcessor,PaliGemmaForConditionalGeneration,)
from transformers.image_utils import load_image
import torch
from transformers import BitsAndBytesConfig
from peft import get_peft_model
from huggingface_hub import login
from PIL import Image
login(api_key)
device = "cuda" if torch.cuda.is_available() else "CPU"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_type=torch.bfloat16
)
# Load base model
model_id = "google/paligemma-3b-pt-224"
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, quantization_config=bnb_config, device_map="auto")
processor = PaliGemmaProcessor.from_pretrained(model_id)
# Load adapter
adapter_path = "digo-prayudha/emotion_classification"
model = PeftModel.from_pretrained(model, adapter_path)
image = Image.open("image.jpg").convert("RGB")
prompt = (
"Classify the emotion expressed in this image."
)
inputs = processor(
text=prompt,
images=image,
return_tensors="pt",
padding="longest",
tokenize_newline_separately=False
).to(model.device)
model.eval()
with torch.no_grad():
outputs = model.generate(**inputs)
decoded_output = processor.decode(outputs[0], skip_special_tokens=True)
print("Predicted Emotion:", decoded_output)
```
## Training procedure
### Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 2e-05
- train_batch_size: 2
- eval_batch_size: 8
- seed: 42
- gradient_accumulation_steps: 2
- total_train_batch_size: 4
- optimizer: Use adamw_hf with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: linear
- lr_scheduler_warmup_steps: 2
- num_epochs: 5
### Training results
| Step | Validation Loss |
|:----:|:---------------:|
| 100 | 2.684700 |
| 200 | 1.282700 |
| 300 | 1.085600 |
| 400 | 0.984500 |
| 500 | 0.861300 |
| 600 | 0.822900 |
| 700 | 0.807100 |
| 800 | 0.753300 |
### Framework versions
- PEFT 0.14.0
- Transformers 4.47.1
- Pytorch 2.5.1+cu121
- Datasets 3.2.0
- Tokenizers 0.21.0 |