You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Repository navigation
Commit da3b32e
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+118-2Lines changed: 118 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ The data structure for unstructured data.
6
6
7
7
🌌 **All data types**: super-expressive data structure for representing complicated/mixed/nested text, image, video, audio, 3D mesh data.
8
8
9
-
🧑🔬 **Data science powerhouse**: easy-to-use functions for facilitating data scientists work on embedding, matching, visualizing unstructured data via Torch/Tensorflow/ONNX/PaddlePaddle.
9
+
🧑🔬 **Data science powerhouse**: easy-to-use functions for facilitating data scientists work on embedding, matching, visualizing, evaluating unstructured data via Torch/Tensorflow/ONNX/PaddlePaddle.
10
10
11
11
🚡 **Portable**: ready to wire with efficient conversion from/to Protobuf, binary, JSON, CSV, dataframe.
12
12
@@ -21,4 +21,120 @@ pip install docarray
21
21
```
22
22
To install full dependencies, please use `pip install docarray[full]`.
23
23
24
-
## [Documentation](https://docarray.jina.ai)
24
+
## [Documentation](https://docarray.jina.ai)
25
+
26
+
## Get Started
27
+
28
+
Let's use DocArray and ResNet50 to build a meme image search on [Totally Looks Like](https://sites.google.com/view/totally-looks-like-dataset). This dataset contains 6016 image-pairs stored in `/left` and `/right`. Images that shares the same filename are labeled as perceptually similar. For example,
29
+
30
+
|`/left`|`/right`|`/left`|`/right`|
31
+
|---------|----------|---------|----------|
32
+
|
33
+
34
+
Our problem is given an image from `/left` and find its most-similar image in `/right` (without looking at the filename of course).
35
+
36
+
### Load images
37
+
38
+
First load images and preprocess them with standard computer vision techniques:
39
+
40
+
```python
41
+
from docarray import DocumentArray, Document
42
+
43
+
left_da = DocumentArray.from_files('left/*.jpg')
44
+
```
45
+
46
+
To get a feeling of the data you will handle, plot them in one sprite image:
47
+
48
+
```python
49
+
left_da.plot_image_sprites()
50
+
```
51
+
52
+
<palign="center">
53
+
<ahref="https://docs.jina.ai"><imgsrc="https://github.com/jina-ai/docarray/blob/master/.github/README-img/sprite.png?raw=true"alt="Load totally looks like dataset with docarray API"width="70%"></a>
54
+
</p>
55
+
56
+
### Apply preprocessing
57
+
58
+
Let's do some standard computer vision preprocessing:
59
+
60
+
```python
61
+
defpreproc(d: Document):
62
+
return (d.load_uri_to_image_blob() # load
63
+
.set_image_blob_normalization() # normalize color
64
+
.set_image_blob_channel_axis(-1, 0)) # switch color axis
65
+
66
+
left_da.apply(preproc)
67
+
```
68
+
69
+
Did I mention `apply` work in parallel?
70
+
71
+
### Embed images
72
+
73
+
Now convert images into embeddings using a pretrained ResNet50:
74
+
75
+
```python
76
+
import torchvision
77
+
model = torchvision.models.resnet50(pretrained=True) # load ResNet50
78
+
left_da.embed(model, device='cuda') # embed via GPU to speedup
79
+
```
80
+
81
+
### Visualize embeddings
82
+
83
+
You can visualize the embeddings via tSNE in an interactive embedding projector:
84
+
85
+
```python
86
+
left_da.plot_embeddings()
87
+
```
88
+
89
+
<palign="center">
90
+
<ahref="https://docs.jina.ai"><imgsrc="https://github.com/jina-ai/docarray/blob/master/.github/README-img/tsne.gif?raw=true"alt="Visualizing embedding via tSNE and embedding projector"width="90%"></a>
91
+
</p>
92
+
93
+
Fun is fun, but recall our goal is to match left images against right images and so far we have only handled the left. Let's repeat the same procedure for the right:
0 commit comments