import os, syssys.path.append(os.path.split(os.path.realpath(__file__))[0] + "/../lib")from cnstream import *from cnstream_cpptest import *# in order to determine whether the python function is called by cppinit_called = Falseexecute_called = Falsepostproc_params = Noneobj_init_called = Falseobj_execute_called = Falseobj_postproc_params = Nonereceived_input_shapes = Nonereceived_output_shape = Noneclass CustomPostproc(Postproc):def __init__(self):Postproc.__init__(self)def init(self, params):global init_calledglobal postproc_paramsinit_called = Truepostproc_params = paramsreturn Truedef execute(self, net_outputs, input_shapes, finfo):global execute_calledexecute_called = Trueglobal received_input_shapesglobal received_output_shapereceived_input_shapes = input_shapesreceived_output_shape = net_outputs[0].shapeclass CustomObjPostproc(ObjPostproc):def __init__(self):ObjPostproc.__init__(self)def init(self, params):global obj_init_calledglobal obj_postproc_paramsobj_init_called = Trueobj_postproc_params = paramsreturn Truedef execute(self, net_outputs, input_shapes, finfo, obj):global obj_execute_calledobj_execute_called = Trueglobal received_input_shapesglobal received_output_shapereceived_input_shapes = input_shapesreceived_output_shape = net_outputs[0].shapeclass TestPostproc:def test_postproc(self):params = {'pyclass_name' : 'test.postproc_test.CustomPostproc', 'param' : 'value'}assert cpptest_pypostproc(params)# test cpp call python init function successassert init_called# test custom parameters from cpp pass to python successassert postproc_params['param'] == 'value'# test cpp call python execute function successassert execute_called# check I/O shapesexpected_input_shapes = [[4, 160, 40, 4]]expected_output_shape = (20, 1, 84)assert expected_input_shapes == received_input_shapesassert expected_output_shape == received_output_shapedef test_obj_postproc(self):params = {'pyclass_name' : 'test.postproc_test.CustomObjPostproc', 'param' : 'value'}assert cpptest_pyobjpostproc(params)# test cpp call python init function successassert obj_init_called# test custom parameters from cpp pass to python successassert obj_postproc_params['param'] == 'value'# test cpp call python execute function successassert obj_execute_called# check I/O shapesexpected_input_shapes = [[4, 160, 40, 4]]expected_output_shape = (20, 1, 84)assert expected_input_shapes == received_input_shapesassert expected_output_shape == received_output_shape
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。