def test_optional_inputs(runner): input_ids = np.array([1, 2]).astype(np.int32) test_model = OptionalInputs() exp0 = test_model(input_ids) exp1 = test_model(input_ids, np.array([1, 2]).astype(np.int32)) oxml = keras2onnx.convert_keras(test_model) assert runner('opt_inputs_0', oxml, [input_ids], exp0) from onnxconverter_common.onnx_fx import GraphFunctionType as _Ty oxml1 = keras2onnx.convert_keras(test_model, initial_types=(_Ty.I32(['N']), _Ty.I32(['N']))) assert runner('opt_inputs_1', oxml1, [input_ids, np.array([1, 2]).astype(np.int32)], exp1)
apply_cast(scope, cast_batch, operator.output_full_names[2], container, to=onnx_proto.TensorProto.INT32) apply_identity(scope, box_batch, operator.output_full_names[0], container) apply_identity(scope, score_batch, operator.output_full_names[1], container) set_converter(YOLONMSLayer, convert_NMSLayer) yolo_model_graph_tiny = None evaluation_model_graph_tiny = None nms_model_graph_tiny = None num_classes = 20 @Graph.trace( input_types=[_Ty.F(shape=['N', 3, 'M1', 'M2']), _Ty.F(shape=['N', 2])], output_types=[_Ty.F(shape=[1, 'M1', 4]), _Ty.F(shape=[1, num_classes, 'M2']), _Ty.I32(shape=[1, 'M3', 3])], outputs=["yolonms_layer_1", "yolonms_layer_1_1", "yolonms_layer_1_2"]) def combine_model_tiny(input_1, image_shape): global yolo_model_graph_tiny global evaluation_model_graph_tiny global nms_model_graph_tiny output_1 = yolo_model_graph_tiny(input_1) input_2 = output_1 + (image_shape,) yolo_evaluation_layer_1, yolo_evaluation_layer_2 = evaluation_model_graph_tiny(*input_2) nms_layer_1_1, nms_layer_1_2, nms_layer_1_3 = nms_model_graph_tiny(yolo_evaluation_layer_1, yolo_evaluation_layer_2) return nms_layer_1_1, nms_layer_1_2, nms_layer_1_3 yolo_model_graph = None evaluation_model_graph = None nms_model_graph = None
set_converter(YOLONMSLayer, convert_NMSLayer) yolo_model_graph_tiny = None evaluation_model_graph_tiny = None nms_model_graph_tiny = None @Graph.trace( input_types=[_Ty.F(shape=['N', 3, 'M1', 'M2']), _Ty.F(shape=['N', 2])], output_types=[ _Ty.F(shape=[1, 'M1', 4]), _Ty.F(shape=[1, 80, 'M2']), _Ty.I32(shape=[1, 'M3', 3]) ], outputs=["yolonms_layer_1", "yolonms_layer_1_1", "yolonms_layer_1_2"]) def combine_model_tiny(input_1, image_shape): global yolo_model_graph_tiny global evaluation_model_graph_tiny global nms_model_graph_tiny output_1 = yolo_model_graph_tiny(input_1) input_2 = output_1 + (image_shape, ) yolo_evaluation_layer_1, yolo_evaluation_layer_2 = evaluation_model_graph_tiny( *input_2) nms_layer_1_1, nms_layer_1_2, nms_layer_1_3 = nms_model_graph_tiny( yolo_evaluation_layer_1, yolo_evaluation_layer_2) return nms_layer_1_1, nms_layer_1_2, nms_layer_1_3
cast_batch, op_version=operator.target_opset, axes=[0]) apply_cast(scope, cast_batch, operator.output_full_names[2], container, to=onnx_proto.TensorProto.INT32) apply_identity(scope, box_batch, operator.output_full_names[0], container) apply_identity(scope, score_batch, operator.output_full_names[1], container) set_converter(YOLONMSLayer, convert_NMSLayer) yolo_model_graph_tiny = None evaluation_model_graph_tiny = None nms_model_graph_tiny = None @Graph.trace( input_types=[_Ty.F(shape=['N', 3, 'M1', 'M2']), _Ty.F(shape=['N', 2])], output_types=[_Ty.F(shape=[1, 'M1', 4]), _Ty.F(shape=[1, 80, 'M2']), _Ty.I32(shape=[1, 'M3', 3])], outputs=["yolonms_layer_1", "yolonms_layer_1_1", "yolonms_layer_1_2"]) def combine_model_tiny(input_1, image_shape): global yolo_model_graph_tiny global evaluation_model_graph_tiny global nms_model_graph_tiny output_1 = yolo_model_graph_tiny(input_1) input_2 = output_1 + (image_shape,) yolo_evaluation_layer_1, yolo_evaluation_layer_2 = evaluation_model_graph_tiny(*input_2) nms_layer_1_1, nms_layer_1_2, nms_layer_1_3 = nms_model_graph_tiny(yolo_evaluation_layer_1, yolo_evaluation_layer_2) return nms_layer_1_1, nms_layer_1_2, nms_layer_1_3 yolo_model_graph = None evaluation_model_graph = None nms_model_graph = None