Luigi commited on
Commit
684ebde
·
1 Parent(s): 18eb8e3

Add 'rtol', 'atol' arguments to control tolerance in model validation

Browse files
Files changed (1) hide show
  1. convert_to_mixed.py +4 -4
convert_to_mixed.py CHANGED
@@ -7,8 +7,6 @@ from onnxconverter_common import auto_mixed_precision_model_path
7
  import argparse
8
 
9
  PROVIDERS=[('TensorrtExecutionProvider', {'trt_fp16_enable':True,}), 'CUDAExecutionProvider', 'CPUExecutionProvider']
10
- RTOL=0.1
11
- ATOL=0.1
12
 
13
  def detect_model_input_size(model_path):
14
  model = onnx.load(model_path)
@@ -46,7 +44,7 @@ def main(args):
46
  input_feed=input_feed,
47
  target_model_path=args.target_model_path,
48
  customized_validate_func=None,
49
- rtol=RTOL, atol=ATOL,
50
  provider=PROVIDERS,
51
  keep_io_types=True,
52
  verbose=True)
@@ -54,7 +52,7 @@ def main(args):
54
  original_result = infer(args.source_model_path, input_feed)
55
  converted_result = infer(args.target_model_path, input_feed)
56
 
57
- is_close = np.allclose(original_result[0], converted_result[0], rtol=RTOL, atol=ATOL)
58
  print(f"Validation result: {'Success' if is_close else 'Failure'}")
59
 
60
  if __name__ == "__main__":
@@ -62,6 +60,8 @@ if __name__ == "__main__":
62
  parser.add_argument("source_model_path", type=str, help="Path to the source ONNX model.")
63
  parser.add_argument("target_model_path", type=str, help="Path where the mixed precision model will be saved.")
64
  parser.add_argument("test_image_path", type=str, help="Path to a test image for validating the model conversion.")
 
 
65
 
66
  args = parser.parse_args()
67
 
 
7
  import argparse
8
 
9
  PROVIDERS=[('TensorrtExecutionProvider', {'trt_fp16_enable':True,}), 'CUDAExecutionProvider', 'CPUExecutionProvider']
 
 
10
 
11
  def detect_model_input_size(model_path):
12
  model = onnx.load(model_path)
 
44
  input_feed=input_feed,
45
  target_model_path=args.target_model_path,
46
  customized_validate_func=None,
47
+ rtol=args.rtol, atol=args.atol,
48
  provider=PROVIDERS,
49
  keep_io_types=True,
50
  verbose=True)
 
52
  original_result = infer(args.source_model_path, input_feed)
53
  converted_result = infer(args.target_model_path, input_feed)
54
 
55
+ is_close = np.allclose(original_result[0], converted_result[0], rtol=args.rtol, atol=args.atol)
56
  print(f"Validation result: {'Success' if is_close else 'Failure'}")
57
 
58
  if __name__ == "__main__":
 
60
  parser.add_argument("source_model_path", type=str, help="Path to the source ONNX model.")
61
  parser.add_argument("target_model_path", type=str, help="Path where the mixed precision model will be saved.")
62
  parser.add_argument("test_image_path", type=str, help="Path to a test image for validating the model conversion.")
63
+ parser.add_argument('--rtol', type=float, default=0.01, help=' the relative tolerance to do validation')
64
+ parser.add_argument('--atol', type=float, default=0.001, help=' the absolute tolerance to do validation')
65
 
66
  args = parser.parse_args()
67