Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(server): docs document tensor #679

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)