-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathtest_proto.py
More file actions
48 lines (31 loc) · 1.08 KB
/
Copy pathtest_proto.py
File metadata and controls
48 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import pytest
import torch
from docarray import BaseDoc, DocArray
from docarray.array import DocArrayStacked
from docarray.typing import NdArray, TorchTensor
@pytest.fixture()
def batch():
class Image(BaseDoc):
tensor: TorchTensor[3, 224, 224]
batch = DocArray[Image]([Image(tensor=torch.zeros(3, 224, 224)) for _ in range(10)])
return batch.stack()
@pytest.mark.proto
def test_proto_stacked_mode_torch(batch):
batch.from_protobuf(batch.to_protobuf())
@pytest.mark.proto
def test_proto_stacked_mode_numpy():
class MyDoc(BaseDoc):
tensor: NdArray[3, 224, 224]
da = DocArray[MyDoc]([MyDoc(tensor=np.zeros((3, 224, 224))) for _ in range(10)])
da = da.stack()
da.from_protobuf(da.to_protobuf())
@pytest.mark.proto
def test_stacked_proto():
class CustomDocument(BaseDoc):
image: NdArray
da = DocArray[CustomDocument](
[CustomDocument(image=np.zeros((3, 224, 224))) for _ in range(10)]
).stack()
da2 = DocArrayStacked.from_protobuf(da.to_protobuf())
assert isinstance(da2, DocArrayStacked)