diff --git a/docs/user-guides/client.md b/docs/user-guides/client.md index c2f0a71df..18f61528d 100644 --- a/docs/user-guides/client.md +++ b/docs/user-guides/client.md @@ -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: diff --git a/tests/test_server.py b/tests/test_server.py index 5d2ff7113..d2bf5b00d 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -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( @@ -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)