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)
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)) input_api.enqueue_image(p, img) 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)
import time if __name__ == "__main__": input_api = InputQueue() base_path = "../../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)