mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-06 22:30:09 +06:00

* Initial commit * more stash commit * Yet another stash commit * yet more stash commit * Mostly working except for docs / repo consistency * Stop importing model list from torch file * Add TF BLIP models to docs * Add auto classes * Move get_text_features and get_image_features * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip_text.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update tests/models/blip/test_modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update tests/models/blip/test_modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Update tests/models/blip/test_modeling_tf_blip_text.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip_text.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Use channels_last convolutions in TF (better performance + compatibility) * Remove _shape function * Move multi-line statement to one line in PT + TF * Specify tf.keras.layers instead of importing from it * Remove test_gradient_checkpointing and empty test_training methods * move some multi-line statements to one line * Update docstring for generate * Remove pruned heads set * Remove self.seq_len_dim * Fixed issues with loss computation, should resolve some tests. Also ensured that the PT version follows the config for output_attentions and output_hidden_states * ensure original model follows config in more cases * Skip the same cross-attention tests in the PT tests - didn't realize we did it twice! * Add training args throughout the models and layers * make fixup * Fix docstring for inputs_embeds * Add docstring for is_decoder * Add docstrings to text models * Remove redundant computation * Add unpack_inputs / keras_serializable * Add modeling_tf_blip to doctests * Add config classes for keras serialization * Changes to allow model porting with pt-to-tf * Quick fix to decoder head and test tweaks * Revert an issue with masking the embeddings outputs * Allow missing keys in some equivalence tests (for unused layers) * Add tf-pt equivalence tests back in * Update src/transformers/models/blip/modeling_tf_blip.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip_text.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update src/transformers/models/blip/modeling_tf_blip_text.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * make fixup * Refactor invert_attention_mask out into tf_utils * Re-enable cross-tests on the PT side too --------- Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
132 lines
3.7 KiB
Plaintext
132 lines
3.7 KiB
Plaintext
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations under the License.
|
|
-->
|
|
|
|
# BLIP
|
|
|
|
## Overview
|
|
|
|
The BLIP model was proposed in [BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation](https://arxiv.org/abs/2201.12086) by Junnan Li, Dongxu Li, Caiming Xiong, Steven Hoi.
|
|
|
|
BLIP is a model that is able to perform various multi-modal tasks including
|
|
- Visual Question Answering
|
|
- Image-Text retrieval (Image-text matching)
|
|
- Image Captioning
|
|
|
|
The abstract from the paper is the following:
|
|
|
|
*Vision-Language Pre-training (VLP) has advanced the performance for many vision-language tasks.
|
|
However, most existing pre-trained models only excel in either understanding-based tasks or generation-based tasks. Furthermore, performance improvement has been largely achieved by scaling up the dataset with noisy image-text pairs collected from the web, which is a suboptimal source of supervision. In this paper, we propose BLIP, a new VLP framework which transfers flexibly to both vision-language understanding and generation tasks. BLIP effectively utilizes the noisy web data by bootstrapping the captions, where a captioner generates synthetic captions and a filter removes the noisy ones. We achieve state-of-the-art results on a wide range of vision-language tasks, such as image-text retrieval (+2.7% in average recall@1), image captioning (+2.8% in CIDEr), and VQA (+1.6% in VQA score). BLIP also demonstrates strong generalization ability when directly transferred to videolanguage tasks in a zero-shot manner. Code, models, and datasets are released.*
|
|
|
|

|
|
|
|
This model was contributed by [ybelkada](https://huggingface.co/ybelkada).
|
|
The original code can be found [here](https://github.com/salesforce/BLIP).
|
|
|
|
## Resources
|
|
|
|
- [Jupyter notebook](https://github.com/huggingface/notebooks/blob/main/examples/image_captioning_blip.ipynb) on how to fine-tune BLIP for image captioning on a custom dataset
|
|
|
|
|
|
## BlipConfig
|
|
|
|
[[autodoc]] BlipConfig
|
|
- from_text_vision_configs
|
|
|
|
## BlipTextConfig
|
|
|
|
[[autodoc]] BlipTextConfig
|
|
|
|
## BlipVisionConfig
|
|
|
|
[[autodoc]] BlipVisionConfig
|
|
|
|
## BlipProcessor
|
|
|
|
[[autodoc]] BlipProcessor
|
|
|
|
|
|
## BlipImageProcessor
|
|
|
|
[[autodoc]] BlipImageProcessor
|
|
- preprocess
|
|
|
|
## BlipModel
|
|
|
|
[[autodoc]] BlipModel
|
|
- forward
|
|
- get_text_features
|
|
- get_image_features
|
|
|
|
## BlipTextModel
|
|
|
|
[[autodoc]] BlipTextModel
|
|
- forward
|
|
|
|
|
|
## BlipVisionModel
|
|
|
|
[[autodoc]] BlipVisionModel
|
|
- forward
|
|
|
|
|
|
## BlipForConditionalGeneration
|
|
|
|
[[autodoc]] BlipForConditionalGeneration
|
|
- forward
|
|
|
|
|
|
## BlipForImageTextRetrieval
|
|
|
|
[[autodoc]] BlipForImageTextRetrieval
|
|
- forward
|
|
|
|
|
|
## BlipForQuestionAnswering
|
|
|
|
[[autodoc]] BlipForQuestionAnswering
|
|
- forward
|
|
|
|
## TFBlipModel
|
|
|
|
[[autodoc]] TFBlipModel
|
|
- call
|
|
- get_text_features
|
|
- get_image_features
|
|
|
|
## TFBlipTextModel
|
|
|
|
[[autodoc]] TFBlipTextModel
|
|
- call
|
|
|
|
|
|
## TFBlipVisionModel
|
|
|
|
[[autodoc]] TFBlipVisionModel
|
|
- call
|
|
|
|
|
|
## TFBlipForConditionalGeneration
|
|
|
|
[[autodoc]] TFBlipForConditionalGeneration
|
|
- call
|
|
|
|
|
|
## TFBlipForImageTextRetrieval
|
|
|
|
[[autodoc]] TFBlipForImageTextRetrieval
|
|
- call
|
|
|
|
|
|
## TFBlipForQuestionAnswering
|
|
|
|
[[autodoc]] TFBlipForQuestionAnswering
|
|
- call |