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

fix: replace transform ndarray with transform blob #910

Merged
merged 3 commits into from
Apr 14, 2023
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
2 changes: 1 addition & 1 deletion server/clip_server/executors/clip_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self._model = CLIPOnnxModel(name, model_path, dtype)
self._tokenizer = Tokenizer(name)

self._image_transform = clip._transform_ndarray(self._model.image_size)
self._image_transform = clip._transform_blob(self._model.image_size)

# define the priority order for the execution providers
providers = ['CPUExecutionProvider']
Expand Down
2 changes: 1 addition & 1 deletion server/clip_server/executors/clip_tensorrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self._model.start_engines()

self._tokenizer = Tokenizer(name)
self._image_transform = clip._transform_ndarray(self._model.image_size)
self._image_transform = clip._transform_blob(self._model.image_size)

if not self.tracer:
self.tracer = NoOpTracer()
Expand Down
2 changes: 1 addition & 1 deletion server/clip_server/executors/clip_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(
name, device=self._device, jit=jit, dtype=dtype, **kwargs
)
self._tokenizer = Tokenizer(name)
self._image_transform = clip._transform_ndarray(self._model.image_size)
self._image_transform = clip._transform_blob(self._model.image_size)

if not self.tracer:
self.tracer = NoOpTracer()
Expand Down
11 changes: 5 additions & 6 deletions server/clip_server/executors/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ def preproc_image(

for d in da:
content = d.content

if d.blob:
d.convert_blob_to_image_tensor()
elif d.tensor is None and d.uri:
if d.tensor is not None:
d.convert_image_tensor_to_blob()
elif d.content_type != 'blob' and d.uri:
# in case user uses HTTP protocol and send data via curl not using .blob (base64), but in .uri
d.load_uri_to_image_tensor()
d.load_uri_to_blob()

tensors_batch.append(preprocess_fn(d.tensor).detach())
tensors_batch.append(preprocess_fn(d.blob).detach())

# recover doc content
d.content = content
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ def test_split_img_txt_da(inputs):
[
Document(
uri='https://clip-as-service.jina.ai/_static/favicon.png',
).load_uri_to_blob(),
).load_uri_to_image_tensor(),
]
)
],
)
def test_preproc_image(inputs):
from clip_server.model import clip

preprocess_fn = clip._transform_ndarray(224)
preprocess_fn = clip._transform_blob(224)
da, pixel_values = preproc_image(inputs, preprocess_fn, drop_image_content=True)
assert len(da) == 1
assert not da[0].blob
Expand Down