본문 바로가기
Linguistic Intelligence/LLM

[LLM] PaliGemma Inference

by goatlab 2024. 7. 30.
728x90
반응형
SMALL

PaliGemma

 

PaliGemma는 PaLI-3에서 영감을 받아 SigLIP 비전 모델 및 Gemma 언어 모델과 같은 개방형 구성 요소를 기반으로 하는 다재다능하고 가벼운 비전 언어 모델 (vision-language model, VLM)이다. 이미지와 텍스트를 모두 입력으로 받고 텍스트를 출력으로 생성하여 여러 언어를 지원한다. 이미지 및 짧은 비디오 캡션, 시각적 질문 답변, 텍스트 읽기, 객체 감지 및 객체 분할과 같은 광범위한 비전 언어 작업에서 동급 최고의 미세 조정 성능을 위해 설계되었다. Transformers PaliGemma 모델의 3B 가중치는 224*224 입력 이미지와 128 토큰 입력/출력 텍스트 시퀀스로 사전 학습되었다. 이 모델은 미세 조정을 위해 float32, bfloat16 및 float16 형식으로 제공된다.

 

예제 코드

 

!pip install -q -U accelerate bitsandbytes git+https://github.com/huggingface/transformers.git
from huggingface_hub import login

login(token="hf_")
import torch
import numpy as np
from PIL import Image
import requests
from transformers import AutoTokenizer, PaliGemmaForConditionalGeneration, PaliGemmaProcessor
import torch

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model_id = "google/paligemma-3b-mix-224"
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16)
processor = PaliGemmaProcessor.from_pretrained(model_id)
input_text = "What approximates the high value on the y-axis of the graph?"
img_path = "test.png"
input_image = Image.open(img_path).convert("RGB")

with torch.no_grad():
  output = model.generate(**inputs, max_length=496)

print(processor.decode(output[0], skip_special_tokens=True))

 

https://huggingface.co/google/paligemma-3b-pt-224

 

google/paligemma-3b-pt-224 · Hugging Face

This repository is publicly accessible, but you have to accept the conditions to access its files and content. To access PaliGemma on Hugging Face, you’re required to review and agree to Google’s usage license. To do this, please ensure you’re logged

huggingface.co

 

728x90
반응형
LIST

'Linguistic Intelligence > LLM' 카테고리의 다른 글

[LLM] Llama 3 모델  (0) 2024.07.29
허깅페이스 (Hugging Face)  (0) 2023.05.09