Files changed (1) hide show
  1. README.md +30 -1
README.md CHANGED
@@ -15,7 +15,36 @@ should probably proofread and complete it, then remove this comment. -->
15
 
16
  # paligemma_race
17
 
18
- This model is a fine-tuned version of [google/paligemma-3b-pt-224](https://huggingface.co/google/paligemma-3b-pt-224) on the imagefolder dataset.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ## Model description
21
 
 
15
 
16
  # paligemma_race
17
 
18
+ This model is a fine-tuned version of [google/paligemma-3b-pt-224](https://huggingface.co/google/paligemma-3b-pt-224) on the FairFace dataset.
19
+
20
+ ``` python
21
+
22
+ from PIL import Image
23
+ import torch
24
+ from transformers import PaliGemmaProcessor, PaliGemmaForConditionalGeneration, BitsAndBytesConfig, TrainingArguments, Trainer
25
+
26
+
27
+ model = PaliGemmaForConditionalGeneration.from_pretrained('NYUAD-ComNets/paligemma_race',torch_dtype=torch.bfloat16)
28
+
29
+ input_text = "what is race of person in the image?"
30
+
31
+ processor = PaliGemmaProcessor.from_pretrained("google/paligemma-3b-pt-224")
32
+
33
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
34
+
35
+ model.to(device)
36
+
37
+
38
+ input_image = Image.open('image_path')
39
+ inputs = processor(text=input_text, images=input_image, padding="longest", do_convert_rgb=True, return_tensors="pt").to(device)
40
+ inputs = inputs.to(dtype=model.dtype)
41
+
42
+ with torch.no_grad():
43
+ output = model.generate(**inputs, max_length=500)
44
+ result=processor.decode(output[0], skip_special_tokens=True)[len(input_text):].strip()
45
+
46
+
47
+ ```
48
 
49
  ## Model description
50