From cbbda0d9537c9ab9c6271b256abc5c972315c211 Mon Sep 17 00:00:00 2001 From: Niels Date: Sat, 25 May 2024 14:14:44 +0200 Subject: [PATCH 1/4] Update docs --- docs/source/en/model_doc/superpoint.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/source/en/model_doc/superpoint.md b/docs/source/en/model_doc/superpoint.md index 56e28622bde9ff..b9aab2f1b929f2 100644 --- a/docs/source/en/model_doc/superpoint.md +++ b/docs/source/en/model_doc/superpoint.md @@ -38,12 +38,17 @@ to repeatedly detect a much richer set of interest points than the initial pre-a traditional corner detector. The final system gives rise to state-of-the-art homography estimation results on HPatches when compared to LIFT, SIFT and ORB.* -## How to use + + + SuperPoint overview. Taken from the original paper. + +## Usage tips Here is a quick example of using the model to detect interest points in an image: ```python -from transformers import AutoImageProcessor, AutoModel +from transformers import AutoImageProcessor, SuperPointForKeypointDetection import torch from PIL import Image import requests @@ -52,7 +57,7 @@ url = "http://images.cocodataset.org/val2017/000000039769.jpg" image = Image.open(requests.get(url, stream=True).raw) processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint") -model = AutoModel.from_pretrained("magic-leap-community/superpoint") +model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint") inputs = processor(image, return_tensors="pt") outputs = model(**inputs) @@ -64,7 +69,7 @@ You can also feed multiple images to the model. Due to the nature of SuperPoint, you will need to use the mask attribute to retrieve the respective information : ```python -from transformers import AutoImageProcessor, AutoModel +from transformers import AutoImageProcessor, SuperPointForKeypointDetection import torch from PIL import Image import requests @@ -77,7 +82,7 @@ image_2 = Image.open(requests.get(url_image_2, stream=True).raw) images = [image_1, image_2] processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint") -model = AutoModel.from_pretrained("magic-leap-community/superpoint") +model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint") inputs = processor(images, return_tensors="pt") outputs = model(**inputs) @@ -103,6 +108,12 @@ cv2.imwrite("output_image.png", image) This model was contributed by [stevenbucaille](https://huggingface.co/stevenbucaille). The original code can be found [here](https://github.com/magicleap/SuperPointPretrainedNetwork). +## Resources + +A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with SuperPoint. If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource. + +- A notebook showcasing inference and visualization with SuperPoint can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/SuperPoint/Inference_with_SuperPoint_to_detect_interest_points_in_an_image.ipynb). 🌎 + ## SuperPointConfig [[autodoc]] SuperPointConfig From bc09c0f7fffb0069e0845cdc0a827cfe35e62422 Mon Sep 17 00:00:00 2001 From: Niels Date: Mon, 27 May 2024 11:25:23 +0200 Subject: [PATCH 2/4] Add PaliGemma resources --- docs/source/en/model_doc/paligemma.md | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/source/en/model_doc/paligemma.md b/docs/source/en/model_doc/paligemma.md index 10946caa83d769..7a065f65619787 100644 --- a/docs/source/en/model_doc/paligemma.md +++ b/docs/source/en/model_doc/paligemma.md @@ -18,11 +18,44 @@ rendered properly in your Markdown viewer. ## Overview -The PaliGemma model was proposed by Google. It is a 3B VLM composed by a Siglip-400m vision encoder and a Gemma-2B decoder linked by a multimodal linear projection. It is not a chat model with images. It cuts an image into a fixed number of VIT tokens and prepends it to an optional prompt. One particularity is that the model uses full block attention on all the image tokens plus the input text tokens. It comes in 3 resolutions, 224x224, 448x448 and 896x896 with 3 base models, with 55 fine-tuned versions for different tasks, and 2 mix models. +The PaliGemma model was proposed in [PaliGemma – Google's Cutting-Edge Open Vision Language Model](https://huggingface.co/blog/paligemma) by Google. It is a 3B vision-language model composed by a [SigLIP](siglip) vision encoder and a [Gemma](gemma) language decoder linked by a multimodal linear projection. It cuts an image into a fixed number of VIT tokens and prepends it to an optional prompt. One particularity is that the model uses full block attention on all the image tokens plus the input text tokens. It comes in 3 resolutions, 224x224, 448x448 and 896x896 with 3 base models, with 55 fine-tuned versions for different tasks, and 2 mix models. + + + PaliGemma architecture. Taken from the blog post. This model was contributed by [Molbap](https://huggingface.co/Molbap). +## Usage tips + +Inference with PaliGemma can be performed as follows: + +```python +from transformers import AutoProcessor, PaliGemmaForConditionalGeneration + +model_id = "google/paligemma-3b-mix-224" +model = PaliGemmaForConditionalGeneration.from_pretrained(model_id) +processor = AutoProcessor.from_pretrained(model_id) + +prompt = "What is on the flower?" +image_file = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg?download=true" +raw_image = Image.open(requests.get(image_file, stream=True).raw) +inputs = processor(prompt, raw_image, return_tensors="pt") +output = model.generate(**inputs, max_new_tokens=20) + +print(processor.decode(output[0], skip_special_tokens=True)[len(prompt):]) +``` + +- PaliGemma is not meant for conversational use, and it works best when fine-tuning to a specific use case. Some downstream tasks on which PaliGemma can be fine-tuned include image captioning, visual question answering (VQA), object detection, referring expression segmentation and document understanding. +- One can use `PaliGemmaProcessor` to prepare all data for the model. + +## Resources + +A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with PaliGemma. If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource. + +- A blog post introducing all the features of PaliGemma can be found [here](https://huggingface.co/blog/paligemma). +- Demo notebooks on how to fine-tune PaliGemma on a custom dataset along with inference can be found [here](https://x.com/mervenoyann/status/1793629910143213687). ## PaliGemmaConfig From 37cf49d1cf61f228a9e34ed095ca6b3c007087c5 Mon Sep 17 00:00:00 2001 From: Niels Date: Mon, 27 May 2024 13:51:19 +0200 Subject: [PATCH 3/4] Address comment --- docs/source/en/model_doc/paligemma.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/en/model_doc/paligemma.md b/docs/source/en/model_doc/paligemma.md index 7a065f65619787..f7f1277d9b20a2 100644 --- a/docs/source/en/model_doc/paligemma.md +++ b/docs/source/en/model_doc/paligemma.md @@ -48,7 +48,13 @@ print(processor.decode(output[0], skip_special_tokens=True)[len(prompt):]) ``` - PaliGemma is not meant for conversational use, and it works best when fine-tuning to a specific use case. Some downstream tasks on which PaliGemma can be fine-tuned include image captioning, visual question answering (VQA), object detection, referring expression segmentation and document understanding. -- One can use `PaliGemmaProcessor` to prepare all data for the model. +- One can use `PaliGemmaProcessor` to prepare images, text and optional labels for the model. When fine-tuning a PaliGemma model, the `suffix` argument can be passed to the processor which creates the `labels` for the model: + +```python +prompt = "What is on the flower?" +answer = "a bee" +inputs = processor(text=prompt, images=raw_image, suffix=answer, return_tensors="pt") +``` ## Resources From dbfe5c746b89bf28821cbb965a22cd7edfe5e9bd Mon Sep 17 00:00:00 2001 From: Niels Date: Tue, 28 May 2024 08:57:34 +0200 Subject: [PATCH 4/4] Update docs --- docs/source/en/model_doc/paligemma.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/en/model_doc/paligemma.md b/docs/source/en/model_doc/paligemma.md index f7f1277d9b20a2..48debe593f97a9 100644 --- a/docs/source/en/model_doc/paligemma.md +++ b/docs/source/en/model_doc/paligemma.md @@ -61,7 +61,8 @@ inputs = processor(text=prompt, images=raw_image, suffix=answer, return_tensors= A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with PaliGemma. If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource. - A blog post introducing all the features of PaliGemma can be found [here](https://huggingface.co/blog/paligemma). -- Demo notebooks on how to fine-tune PaliGemma on a custom dataset along with inference can be found [here](https://x.com/mervenoyann/status/1793629910143213687). +- Demo notebooks on how to fine-tune PaliGemma for VQA with the Trainer API along with inference can be found [here](https://github.com/huggingface/notebooks/tree/main/examples/paligemma). +- Demo notebooks on how to fine-tune PaliGemma on a custom dataset (receipt image -> JSON) along with inference can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/PaliGemma). 🌎 ## PaliGemmaConfig