(model_opt: onnx.ModelProto, model_ori: onnx.ModelProto, n_times: int = 5,
          input_shapes: Optional[TensorShapes] = None, custom_lib: Optional[str] = None)
return True
Warning: Some models (e.g., MobileNet) may fail this check by a small magnitude.
    Just ignore if it happens.
    :param input_shapes: Shapes of generated random inputs
    :param model_opt: The simplified ONNX model
    :param model_ori: The original ONNX model
    :param n_times: Generate n random inputs
Warning: Some models (e.g., MobileNet) may fail this check by a small magnitude.
    Just ignore if it happens.
    :param input_shapes: Shapes of generated random inputs
    :param model_opt: The simplified ONNX model
    :param model_ori: The original ONNX model
    :param n_times: Generate n random inputs
Warning : Some models ( e . g . MobileNet ) may fail this check by a small magnitude . Just ignore if it happens . : param input_shapes : Shapes of generated random inputs : param model_opt : The simplified ONNX model : param model_ori : The original ONNX model : param n_times : Generate n random inputs
def check(model_opt: onnx.ModelProto, model_ori: onnx.ModelProto, n_times: int = 5,
          input_shapes: Optional[TensorShapes] = None, custom_lib: Optional[str] = None) -> bool:
    """
    Warning: Some models (e.g., MobileNet) may fail this check by a small magnitude.
    Just ignore if it happens.
    :param input_shapes: Shapes of generated random inputs
    :param model_opt: The simplified ONNX model
    :param model_ori: The original ONNX model
    :param n_times: Generate n random inputs
    """
    if input_shapes is None:
        input_shapes = {}
    onnx.checker.check_model(model_opt)

    if is_non_deterministic_model(model_ori) and n_times > 0:
        print("The model has random ops like RandomNormal. Skip checking..")
        n_times = 0

    for i in range(n_times):
        print("Checking {}/{}...".format(i, n_times))
        rand_input = generate_all_rand_input(
            model_opt, input_shapes=input_shapes)
        res_opt = forward(model_opt, input_data=rand_input, custom_lib=custom_lib)
        res_ori = forward(model_ori, input_data=rand_input, custom_lib=custom_lib)

        for name in res_opt.keys():
            if not np.allclose(res_opt[name], res_ori[name], rtol=1e-4, atol=1e-5):
                print("Tensor {} changes after simplifying. The max diff is {}.".format(
                    name, np.max(np.abs(res_opt[name] - res_ori[name]))))
                print("Note that the checking is not always correct.")
                print("After simplifying:")
                print(res_opt[name])
                print("Before simplifying:")
                print(res_ori[name])
                print("----------------")
                return False
    return True
def check ( model_opt : onnx . ModelProto , model_ori : onnx . ModelProto , n_times : int = 5 , input_shapes : Optional [ TensorShapes ] = None , custom_lib : Optional [ str ] = None ) -> bool : if input_shapes is None : input_shapes = { } onnx . checker . check_model ( model_opt ) if is_non_deterministic_model ( model_ori ) and n_times > 0 : print ( "The model has random ops like RandomNormal. Skip checking.." ) n_times = 0 for i in range ( n_times ) : print ( "Checking {}/{}..." . format ( i , n_times ) ) rand_input = generate_all_rand_input ( model_opt , input_shapes = input_shapes ) res_opt = forward ( model_opt , input_data = rand_input , custom_lib = custom_lib ) res_ori = forward ( model_ori , input_data = rand_input , custom_lib = custom_lib ) for name in res_opt . keys ( ) : if not np . allclose ( res_opt [ name ] , res_ori [ name ] , rtol = 1e-4 , atol = 1e-5 ) : print ( "Tensor {} changes after simplifying. The max diff is {}." . format ( name , np . max ( np . abs ( res_opt [ name ] - res_ori [ name ] ) ) ) ) print ( "Note that the checking is not always correct." ) print ( "After simplifying:" ) print ( res_opt [ name ] ) print ( "Before simplifying:" ) print ( res_ori [ name ] ) print ( "----------------" ) return False return True