Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3@brief Optimisations of :epkg:`ONNX` graphs. 

4""" 

5from ._onnx_optimisation_common import _apply_optimisation_on_graph 

6from .onnx_optimisation_identity import onnx_remove_node_identity 

7from .onnx_optimisation_redundant import onnx_remove_node_redundant 

8from .onnx_optimisation_unused import onnx_remove_node_unused 

9 

10 

11def onnx_remove_node(onnx_model, recursive=True, debug_info=None, **options): 

12 """ 

13 Removes as many nodes as possible without changing 

14 the outcome. It applies @see fn onnx_remove_node_identity, 

15 then @see fn onnx_remove_node_redundant. 

16 

17 @param onnx_model onnx model 

18 @param recursive looks into subgraphs 

19 @param debug_info debug information (private) 

20 @param options additional options 

21 @return new onnx _model 

22 """ 

23 if debug_info is None: 

24 debug_info = [str(type(onnx_model)).split('.')[-1].strip("'>")] 

25 else: 

26 debug_info = debug_info + \ 

27 [str(type(onnx_model)).split('.')[-1].strip("'>")] 

28 

29 if hasattr(onnx_model, 'graph'): 

30 return _apply_optimisation_on_graph( 

31 onnx_remove_node, onnx_model, 

32 recursive=recursive, debug_info=debug_info, 

33 **options) 

34 

35 graph = onnx_model 

36 graph = onnx_remove_node_unused( 

37 graph, recursive=recursive, debug_info=debug_info, **options) 

38 graph = onnx_remove_node_identity( 

39 graph, recursive=recursive, debug_info=debug_info, **options) 

40 graph = onnx_remove_node_redundant( 

41 graph, recursive=recursive, debug_info=debug_info, **options) 

42 return graph