Esempio n. 1
0
 def test_input_queue_with_frontend(self):
     input_api = InputQueue(host="1.1.1.1",
                            port="1111",
                            name="my-test",
                            frontend_url="1.1.1.1:1")
     input_api2 = InputQueue(frontend_url="1.1.1.1:1")
     assert input_api.name == "my-test"
     assert input_api.host == "1.1.1.1"
     assert input_api.port == "1111"
     assert input_api.frontend_url == "1.1.1.1:1"
     assert input_api2.frontend_url == "1.1.1.1:1"
def run(path):
    input_api = InputQueue()
    base_path = path

    if not base_path:
        raise EOFError("You have to set your image path")
    output_api = OutputQueue()
    output_api.dequeue()
    path = os.listdir(base_path)
    for p in path:
        if not p.endswith("jpeg"):
            continue
        img = cv2.imread(os.path.join(base_path, p))
        img = cv2.resize(img, (224, 224))
        data = cv2.imencode(".jpg", img)[1]
        img_encoded = base64.b64encode(data).decode("utf-8")
        input_api.enqueue(p, t={"b64": img_encoded})

    time.sleep(10)

    # get all result and dequeue
    result = output_api.dequeue()
    for k in result.keys():
        output = "image: " + k + ", classification-result:"
        tmp_list = json.loads(result[k])
        for record in range(len(tmp_list)):
            output += " class: " + str(tmp_list[record][0]) \
                      + "'s prob: " + str(tmp_list[record][1])
        print(output)
def image_enqueue(redis_args, img_num, proc_num, path, encrypt):
    print("Entering enqueue")
    input_api = InputQueue(**redis_args)
    img = cv2.imread(path)
    img = cv2.resize(img, (224, 224))
    data = cv2.imencode(".jpg", img)[1]
    img_encoded = base64.b64encode(data).decode("utf-8")
    if encrypt:
        img_encoded = encrypt_with_AES_GCM(img_encoded, "secret", "salt")
        print("Record encoded")

    img_per_proc = int(img_num / proc_num)
    procs = []

    def push_image(image_num, index, proc_id):
        print("Entering enqueue", proc_id)
        for i in range(image_num):
            input_api.enqueue("my-img-" + str(i + index), t={"b64": img_encoded})

    start = time.time()
    for i in range(proc_num):
        proc = Process(target=push_image, args=(img_per_proc, i * img_per_proc, i,))
        procs.append(proc)
        proc.start()

    for p in procs:
        p.join()

    end = time.time()
    print(img_num, "images enqueued")
    print("total enqueue time:", end - start)
    fps = img_num / (end - start)
    print("enqueue fps:", fps)

    return start
Esempio n. 4
0
def run():
    input_api = InputQueue()

    base_path = os.path.abspath(
        __file__ + "/../../../test/zoo/resources/serving_quick_start")

    if not base_path:
        raise EOFError("You have to set your image path")
    output_api = OutputQueue()
    output_api.dequeue()
    path = os.listdir(base_path)
    for p in path:
        if not p.endswith("jpeg"):
            continue
        img = cv2.imread(os.path.join(base_path, p))
        img = cv2.resize(img, (224, 224))
        input_api.enqueue_image(p, img)

    time.sleep(5)

    # get all result and dequeue
    result = output_api.dequeue()
    for k in result.keys():
        output = "image: " + k + ", classification-result:"
        tmp_dict = json.loads(result[k])
        for class_idx in tmp_dict.keys():
            output += "class: " + class_idx + "'s prob: " + tmp_dict[class_idx]
        print(output)
Esempio n. 5
0
def run(path):
    input_api = InputQueue()
    base_path = path

    if not base_path:
        raise EOFError("You have to set your image path")
    output_api = OutputQueue()
    output_api.dequeue()
    path = [os.path.join(base_path, "cat1.jpeg")]
    for p in path:
        if not p.endswith("jpeg"):
            continue
        img = cv2.imread(p)
        img = cv2.resize(img, (224, 224))
        data = cv2.imencode(".jpg", img)[1]
        img_encoded = base64.b64encode(data).decode("utf-8")
        result = input_api.enqueue("cat", t={"b64": img_encoded})

    time.sleep(10)

    cat_image_prediction = output_api.query("cat")
    print("cat prediction layer shape: ", cat_image_prediction.shape)
    class_idx = np.argmax(cat_image_prediction)
    print("the class index of prediction of cat image result: ", class_idx)

    # get all result and dequeue
    result = output_api.dequeue()
    for k in result.keys():
        prediction = output_api.get_ndarray_from_b64(result[k])
        # this prediction is the same as the cat_image_prediction above
        print(k, "prediction layer shape: ", prediction.shape)
Esempio n. 6
0
 def test_default_config(self):
     input_api = InputQueue()
     output_api = OutputQueue()
     assert input_api.name == "serving_stream"
     assert input_api.host == "localhost"
     assert input_api.port == "6379"
     assert output_api.name == "serving_stream"
     assert output_api.host == "localhost"
     assert output_api.port == "6379"
Esempio n. 7
0
def run():
    input_api = InputQueue()
    output_api = OutputQueue()
    output_api.dequeue()

    import numpy as np
    a = np.array([1, 2])
    input_api.enqueue('a', p=a)

    time.sleep(5)
    print(output_api.query('a'))
Esempio n. 8
0
#
# Copyright 2018 Analytics Zoo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from zoo.serving.client import InputQueue, OutputQueue
import numpy as np
# input tensor
x = np.array([2, 3], dtype=np.float32)

input_api = InputQueue()
input_api.enqueue_tensor('my_input', input=x)

output_api = OutputQueue()
result = output_api.query('my_input')
print("Result is :" + str(result))
Esempio n. 9
0
 def test_encode(self):
     input_api = InputQueue()
     b64 = input_api.data_to_b64(t1=np.array([1, 2]), t2=np.array([3, 4]))
     byte = base64.b64decode(b64)
Esempio n. 10
0
 def open(self, function_context: FunctionContext):
     self._input_api = InputQueue(
         host="localhost",
         port="6379",
         sync=True,
         frontend_url="http://127.0.0.1:10020")
Esempio n. 11
0
 def test_input_queue_without_frontend(self):
     input_api = InputQueue(host="1.1.1.1", port="1111", name="my-test")
     assert input_api.name == "my-test"
     assert input_api.host == "1.1.1.1"
     assert input_api.port == "1111"
     assert not input_api.frontend_url