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 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'))
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)
# # 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('my_input', input=x) output_api = OutputQueue() result = output_api.query('my_input') print("Result is :" + str(result))