logo
Browse Source

revise the doc.

Signed-off-by: wxywb <xy.wang@zilliz.com>
main
wxywb 2 years ago
parent
commit
3af8abd963
  1. 54
      README.md
  2. BIN
      cap.png
  3. BIN
      tabular.png
  4. BIN
      tabular1.png
  5. BIN
      tabular2.png
  6. BIN
      vec1.png
  7. BIN
      vec2.png

54
README.md

@ -1,4 +1,4 @@
# Image-Text Retrieval Embdding with BLIP
# Image Captioning with BLIP
*author: David Wang* *author: David Wang*
@ -9,7 +9,7 @@
## Description ## Description
This operator extracts features for image or text with [BLIP](https://arxiv.org/abs/2201.12086) which can generate embeddings for text and image by jointly training an image encoder and text encoder to maximize the cosine similarity. This is a adaptation from [salesforce/BLIP](https://github.com/salesforce/BLIP).
This operator generates the caption with [BLIP](https://arxiv.org/abs/2201.12086) which describes the content of the given image. This is an adaptation from [salesforce/BLIP](https://github.com/salesforce/BLIP).
<br /> <br />
@ -17,45 +17,33 @@ This operator extracts features for image or text with [BLIP](https://arxiv.org/
## Code Example ## Code Example
Load an image from path './teddy.jpg' to generate an image embedding.
Read the text 'A teddybear on a skateboard in Times Square.' to generate an text embedding.
Load an image from path './animals.jpg' to generate the caption.
*Write the pipeline in simplified style*: *Write the pipeline in simplified style*:
```python ```python
import towhee import towhee
towhee.glob('./teddy.jpg') \
towhee.glob('./animals.jpg') \
.image_decode() \ .image_decode() \
.image_text_embedding.blip(model_name='blip_base', modality='image') \
.show()
towhee.dc(["A teddybear on a skateboard in Times Square."]) \
.image_text_embedding.blip(model_name='blip_base', modality='text') \
.image_captioning.blip(model_name='blip_base') \
.select() \
.show() .show()
``` ```
<img src="https://towhee.io/image-text-embedding/blip/raw/branch/main/vec1.png" alt="result1" style="height:20px;"/>
<img src="https://towhee.io/image-text-embedding/blip/raw/branch/main/vec2.png" alt="result2" style="height:20px;"/>
<img src="./cap.png" alt="result1" style="height:20px;"/>
*Write a same pipeline with explicit inputs/outputs name specifications:* *Write a same pipeline with explicit inputs/outputs name specifications:*
```python ```python
import towhee import towhee
towhee.glob['path']('./teddy.jpg') \
towhee.glob['path']('./animals.jpg') \
.image_decode['path', 'img']() \ .image_decode['path', 'img']() \
.image_text_embedding.blip['img', 'vec'](model_name='blip_base', modality='image') \
.select['img', 'vec']() \
.show()
towhee.dc['text'](["A teddybear on a skateboard in Times Square."]) \
.image_text_embedding.blip['text','vec'](model_name='blip_base', modality='text') \
.select['text', 'vec']() \
.image_captioning.blip['img', 'text'](model_name='blip_base') \
.select['img', 'text']() \
.show() .show()
``` ```
<img src="https://towhee.io/image-text-embedding/blip/raw/branch/main/tabular1.png" alt="result1" style="height:60px;"/>
<img src="https://towhee.io/image-text-embedding/blip/raw/branch/main/tabular2.png" alt="result2" style="height:60px;"/>
<img src="./tabular.png" alt="result2" style="height:60px;"/>
<br /> <br />
@ -66,7 +54,7 @@ towhee.dc['text'](["A teddybear on a skateboard in Times Square."]) \
Create the operator via the following factory method Create the operator via the following factory method
***blip(model_name, modality)***
***blip(model_name)***
**Parameters:** **Parameters:**
@ -75,33 +63,23 @@ Create the operator via the following factory method
​ The model name of BLIP. Supported model names: ​ The model name of BLIP. Supported model names:
- blip_base - blip_base
***modality:*** *str*
​ Which modality(*image* or *text*) is used to generate the embedding.
<br /> <br />
## Interface ## Interface
An image-text embedding operator takes a [towhee image](link/to/towhee/image/api/doc) or string as input and generate an embedding in ndarray.
An image-text embedding operator takes a [towhee image](link/to/towhee/image/api/doc) as input and generate the correspoing caption.
**Parameters:** **Parameters:**
***data:*** *towhee.types.Image (a sub-class of numpy.ndarray)* or *str* ***data:*** *towhee.types.Image (a sub-class of numpy.ndarray)* or *str*
​ The data (image or text based on specified modality) to generate embedding.
**Returns:** *numpy.ndarray*
​ The data embedding extracted by model.
​ The image to generate embedding.
**Returns:** *str*
​ The caption generated by model.

BIN
cap.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

BIN
tabular.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

BIN
tabular1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 KiB

BIN
tabular2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

BIN
vec1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

BIN
vec2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save