Skip to content

Commit

Permalink
docs(server): docs document tensor (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao authored Apr 11, 2022
1 parent 8b800ee commit b6f9d84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/user-guides/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ This feature uses [DocArray](https://docarray.jina.ai), which is installed toget

If auto-detection on a list of raw string is too "sci-fi" to you, then you may use `docarray.Document` to make the input more explicit and organized. `Document` can be used as a container to easily represent a sentence or an image.

- Input: each Document must be filled with `.text` or `.uri` or `.blob` attribute. Document filled with `.text` is considered as sentence, Document filled with `.uri` or `.blob` is considered as image.
- Input: each Document must be filled with `.text` or `.uri` or `.blob` or `.tensor` attribute.
- Document filled with `.text` is considered as sentence;
- Document filled with `.uri` or `.blob` or `.tensor` is considered as image. If `.tensor` is filled, then its shape must be in `[H, W, C]` format.
- Output: a `DocumentArray` of the same input length. Each Document in it is now filled with `.embedding` attribute.

The explicit comes from now you have to put the string into the Document attributes. For example, we can rewrite the above example as below:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from clip_server.model.clip import _transform_ndarray, _transform_blob
from docarray import Document
import numpy as np


@pytest.mark.parametrize(
Expand All @@ -22,3 +23,16 @@ def test_server_preprocess_ndarray_image(image_uri, size):
t1 = _transform_blob(size)(d1.blob).numpy()
t2 = _transform_ndarray(size)(d2.tensor).numpy()
assert t1.shape == t2.shape


@pytest.mark.parametrize(
'tensor',
[
np.random.random([100, 100, 3]),
np.random.random([1, 1, 3]),
np.random.random([5, 50, 3]),
],
)
def test_transform_arbitrary_tensor(tensor):
d = Document(tensor=tensor)
assert _transform_ndarray(224)(d.tensor).numpy().shape == (3, 224, 224)

0 comments on commit b6f9d84

Please sign in to comment.