def test_build_failed(self): conf_file = test_config.TEST_DATA_DIR + "/py_config.toml" driver_dir = test_config.TEST_DRIVER_DIR txt = r""" [driver] dir=["{}"] skip-default=true [log] level="ERROR" [graph] graphconf = '''digraph demo {{ notexist[type=flowunit, flowunit=notexist, device=cpu] }}''' format = "graphviz" """.format(driver_dir) conf = modelbox.Configuration() flow = modelbox.Flow() ret = flow.init("graph", txt) if ret == False: self.assertTrue(ret) self.assertTrue(ret) ret = flow.build() if ret == False: modelbox.error(ret) self.assertFalse(ret)
def thread_func(self, flow, conf_file): ret = flow.init(conf_file) if ret == False: modelbox.error(ret) self.assertTrue(ret) ret = flow.build() self.assertTrue(ret) ret = flow.run_async() self.assertTrue(ret) retval = modelbox.Status() ret = flow.wait(0, retval) self.assertEqual(retval, modelbox.Status.StatusCode.STATUS_STOP)
def test_flow_op(self): conf_file = test_config.TEST_DATA_DIR + "/py_op_config.toml" driver_dir = test_config.TEST_DRIVER_DIR with open(conf_file, "w") as out: txt = r""" [driver] dir=["{}", "{}"] skip-default=true [log] level="INFO" [graph] graphconf = '''digraph demo {{ python_image[type=flowunit, flowunit=python_image, device=cpu, deviceid=0, label="<image_out/out_1>", batch_size = 10] python_resize[type=flowunit, flowunit=python_resize, device=cpu, deviceid=0, label="<resize_in> | <resize_out>"] python_brightness[type=flowunit, flowunit=python_brightness, device=cpu, deviceid=0, label="<brightness_in> | <brightness_out>", brightness = 0.1] python_show[type=flowunit, flowunit=python_show, device=cpu, deviceid=0, label="<show_in>", is_save = true] python_image:"image_out/out_1" -> python_resize:resize_in python_resize:resize_out -> python_brightness:brightness_in python_brightness:brightness_out -> python_show:show_in }}''' format = "graphviz" """.format(driver_dir, test_config.TEST_DATA_DIR + "/python_op") out.write(txt) conf = modelbox.Configuration() flow = modelbox.Flow() ret = flow.init(conf_file) os.remove(conf_file) if ret == False: modelbox.error(ret) self.assertTrue(ret) ret = flow.build() self.assertTrue(ret) ret = flow.run_async() self.assertTrue(ret) retval = modelbox.Status() ret = flow.wait(0, retval) self.assertEqual(retval, modelbox.Status.StatusCode.STATUS_STOP)
def test_flow_for_buffer(self): conf_file = test_config.TEST_DATA_DIR + "/py_op_config.toml" driver_dir = test_config.TEST_DRIVER_DIR with open(conf_file, "w") as out: txt = r""" [driver] dir=["{}", "{}"] skip-default=true [log] level="INFO" [graph] graphconf = '''digraph demo {{ input1[type=input] python_buffer[type=flowunit, flowunit=python_buffer, device=cpu, deviceid=0, label="<buffer_in> | <buffer_out>", buffer_config = 0.2] output1[type=output] input1 -> python_buffer:buffer_in python_buffer:buffer_out -> output1 }}''' format = "graphviz" """.format(driver_dir, test_config.TEST_DATA_DIR + "/python_op") out.write(txt) conf = modelbox.Configuration() flow = modelbox.Flow() ret = flow.init(conf_file) os.remove(conf_file) if ret == False: modelbox.error(ret) self.assertTrue(ret) ret = flow.build() self.assertTrue(ret) ret = flow.run_async() self.assertTrue(ret) img = cv2.imread(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) with Image.open(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") as img: img_np = np.array(img) extern_data_map = flow.create_external_data_map() buffer_list = extern_data_map.create_buffer_list() buffer_list.push_back(img_np) extern_data_map.send("input1", buffer_list) extern_data_map.shutdown() buffer_list_map = modelbox.ExtOutputBufferList() ret = extern_data_map.recv(buffer_list_map) self.assertTrue(ret) result_buffer_list = buffer_list_map.get_buffer_list("output1") for i in range(result_buffer_list.size()): buffer = result_buffer_list[i] np_image = np.array(buffer, copy= False) image = Image.fromarray(np_image) with Image.open(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") as check_image: try: check_image_np = np.array(check_image) diff = ImageChops.difference(image, Image.fromarray(check_image_np)) self.assertEqual(diff.getbbox(), None) except ValueError as e: flow.stop() self.assertTrue(False) data_type = buffer.get("type") if data_type != modelbox.Buffer.ModelBoxDataType.UINT8: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid type") float_test = buffer.get("float_test") if float_test != 0.5: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid float test") string_test = buffer.get("string_test") if string_test != "TEST": return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid string test") int_test = buffer.get("int_test") if int_test != 100: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid int test") bool_test = buffer.get("bool_test") if bool_test != False: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid bool test") int_list = buffer.get("list_int_test") if int_list != [1, 1, 1]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid int list") float_list = buffer.get("list_float_test") if float_list != [0.1, 0.2, 0.3]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid float list") bool_list = buffer.get("list_bool_test") if bool_list != [False, False, True]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid bool list") string_list = buffer.get("list_string_test") if string_list != ["TEST1", "TEST2", "TEST3"]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid string list") try: dict_test = buffer.get("map_test") except ValueError as err: modelbox.info(str(err)) else: flow.stop() self.assertTrue(False) flow.stop()
def test_flow_op_ext(self): conf_file = test_config.TEST_DATA_DIR + "/py_op_config.toml" driver_dir = test_config.TEST_DRIVER_DIR with open(conf_file, "w") as out: txt = r""" [driver] dir=["{}", "{}"] skip-default=true [log] level="INFO" [graph] graphconf = '''digraph demo {{ input1[type=input] python_resize[type=flowunit, flowunit=python_resize, device=cpu, deviceid=0, label="<resize_in> | <resize_out>"] python_brightness[type=flowunit, flowunit=python_brightness, device=cpu, deviceid=0, label="<brightness_in> | <brightness_out>", brightness = 0.1] output1[type=output] input1 -> python_resize:resize_in python_resize:resize_out -> python_brightness:brightness_in python_brightness:brightness_out -> output1 }}''' format = "graphviz" """.format(driver_dir, test_config.TEST_DATA_DIR + "/python_op") out.write(txt) conf = modelbox.Configuration() flow = modelbox.Flow() ret = flow.init(conf_file) os.remove(conf_file) if ret == False: modelbox.error(ret) self.assertTrue(ret) ret = flow.build() self.assertTrue(ret) ret = flow.run_async() self.assertTrue(ret) img = cv2.imread(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) extern_data_map = flow.create_external_data_map() buffer_list = extern_data_map.create_buffer_list() im_array = np.asarray(img_rgb[:,:]) buffer_list.push_back(im_array) extern_data_map.send("input1", buffer_list) extern_data_map.shutdown() buffer_list_map = modelbox.ExtOutputBufferList() ret = extern_data_map.recv(buffer_list_map) self.assertTrue(ret) result_buffer_list = buffer_list_map.get_buffer_list("output1") for i in range(result_buffer_list.size()): aa = result_buffer_list[i] np_image = np.array(aa, copy= False) image = Image.fromarray(np_image) with Image.open(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/python_test_show_out.png") as check_image: try: diff = ImageChops.difference(image, check_image) self.assertEqual(diff.getbbox(), None) except ValueError as e: self.assertTrue(False) flow.stop()