FastJobs/Visual_Emotional_Analysis
Viewer • Updated • 800 • 591 • 14
How to use digo-prayudha/emotion_classification with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("google/paligemma-3b-pt-224")
model = PeftModel.from_pretrained(base_model, "digo-prayudha/emotion_classification")This model is a fine-tuned version of google/paligemma-3b-pt-224 on the FastJobs/Visual_Emotional_Analysis dataset.
This model was trained on the FastJobs/Visual_Emotional_Analysis dataset.
The dataset contains:
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)
The following hyperparameters were used during training:
| 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 |
Base model
google/paligemma-3b-pt-224