Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting PaliGemma transformers checkpoint #1686

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

ariG23498
Copy link
Collaborator

Porting Pali Gemma transformers checkpoints in Keras NLP

@github-actions github-actions bot added the Gemma Gemma model specific issues label Jul 7, 2024
@ariG23498
Copy link
Collaborator Author

The working colab notebook: Notebook

@ariG23498 ariG23498 changed the title [WIP] Porting PaliGemma transformers checkpoint Porting PaliGemma transformers checkpoint Jul 7, 2024
@ariG23498 ariG23498 marked this pull request as ready for review July 7, 2024 12:54
@ariG23498 ariG23498 added the kokoro:force-run Runs Tests on GPU label Jul 7, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Jul 7, 2024
@ariG23498
Copy link
Collaborator Author

ariG23498 commented Jul 7, 2024

With this I got to run a fine-tuned captioning model

!pip install -U -q git+https://github.com/ariG23498/keras-nlp@aritra/paligemma-hf-port
!pip install -U -q keras

import os
os.environ["KERAS_BACKEND"] = "jax"

import keras_nlp

import requests
from PIL import Image
import numpy as np

pali_gemma_lm = keras_nlp.models.PaliGemmaCausalLM.from_preset(
    "hf://gokaygokay/sd3-long-captioner"
)

url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg"

image = Image.open(requests.get(url, stream=True).raw).resize((224, 224))
image = np.array(image)

pali_gemma_lm.generate({
    "images": image,
    "prompts": "caption en "
})

Which generates

caption en captured from a high-angle perspective, a light blue vintage car is parked on a cobblestone street,
its side facing the viewer. the car's body is adorned with a silver trim, adding a touch of elegance to its
appearance. the windows of the car are tinted, providing a glimpse of the interior. the car's wheels, a striking
feature, are adorned with a silver hub cap, adding a touch of elegance to the overall design. the backdrop
features a weathered yellow wall, its texture enhanced by the peeling paint on its surface. to the left of the
frame, a brown wooden door with arched top panels is visible, adding a touch of rustic charm to the scene.

The image in question 👇

image

Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mattdangerw mattdangerw merged commit a00efc2 into keras-team:master Jul 8, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gemma Gemma model specific issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants