NYUAD-ComNets commited on
Commit
5016cfc
·
verified ·
1 Parent(s): 8a39efb

Update README.md

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