Exemplo n.º 1
0
def test_input_files(patterns, recursive, size, sampling_rate, read_mode):
    Client.check_input(
        DocumentArray.from_files(
            patterns=patterns,
            recursive=recursive,
            size=size,
            sampling_rate=sampling_rate,
            read_mode=read_mode,
        ))
Exemplo n.º 2
0
def test_mime_type(restful):
    class MyExec(Executor):
        @req
        def foo(self, docs: 'DocumentArray', **kwargs):
            for d in docs:
                d.convert_uri_to_buffer()

    f = Flow(restful=restful).add(uses=MyExec)

    def validate_mime_type(req):
        for d in req.data.docs:
            assert d.mime_type == 'text/x-python'

    with f:
        f.index(DocumentArray.from_files('*.py'), validate_mime_type)
Exemplo n.º 3
0
def preproc(d: Document):
    return (
        d.load_uri_to_image_blob()  # load
        .set_image_blob_shape(shape=(224, 224))
        .set_image_blob_normalization()  # normalize color
        .set_image_blob_channel_axis(-1, 0)
    )  # switch color axis


if __name__ == '__main__':
    base_path = r'C:\Users\computer\pictures'
    search_extension = '*.jpg'
    query_image = '1.jpg'

    docs = DocumentArray.from_files(os.path.join(base_path, search_extension)).apply(preproc)

    model = torchvision.models.resnet50(pretrained=True)  # load ResNet50
    docs.embed(model, device='cuda')  # embed via GPU to speedup

    # q = (
    #     Document(uri=os.path.join(base_path, query_image))  # build query image & preprocess
    #     .load_uri_to_image_blob()
    #     .set_image_blob_shape(shape=(512, 512))
    #     .set_image_blob_normalization()
    #     .set_image_blob_channel_axis(-1, 0)
    # )
    #

    q = preproc(Document(uri=os.path.join(base_path, query_image)))
    q.embed(model)  # embed
Exemplo n.º 4
0
def test_input_files_with_invalid_read_mode():
    with pytest.raises(BadClientInput):
        Client.check_input(
            DocumentArray.from_files(patterns='*.*', read_mode='invalid'))