Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/saved_model/main_op_impl.py: 67%

21 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

1# Copyright 2015 The TensorFlow Authors. All Rights Reserved. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================== 

15"""SavedModel main op implementation.""" 

16 

17from tensorflow.python.framework import ops 

18from tensorflow.python.ops import control_flow_ops 

19from tensorflow.python.ops import lookup_ops 

20from tensorflow.python.ops import variables 

21from tensorflow.python.util import deprecation 

22from tensorflow.python.util.tf_export import tf_export 

23 

24_DEPRECATION_MSG = ( 

25 'This API was designed for TensorFlow v1. See ' 

26 'https://www.tensorflow.org/guide/migrate for instructions on how to ' 

27 'migrate your code to TensorFlow v2.') 

28 

29 

30@tf_export(v1=['saved_model.main_op.main_op']) 

31@deprecation.deprecated(None, _DEPRECATION_MSG) 

32def main_op(): 

33 """Returns a main op to init variables and tables. 

34 

35 Returns the main op including the group of ops that initializes all 

36 variables, initializes local variables and initialize all tables. 

37 

38 Returns: 

39 The set of ops to be run as part of the main op upon the load operation. 

40 """ 

41 init = variables.global_variables_initializer() 

42 init_local = variables.local_variables_initializer() 

43 init_tables = lookup_ops.tables_initializer() 

44 return control_flow_ops.group(init, init_local, init_tables) 

45 

46 

47# TODO(sukritiramesh): Integrate with Saver for complete restore functionality. 

48@tf_export(v1=['saved_model.main_op_with_restore', 

49 'saved_model.main_op.main_op_with_restore']) 

50@deprecation.deprecated(None, _DEPRECATION_MSG) 

51def main_op_with_restore(restore_op_name): 

52 """Returns a main op to init variables, tables and restore the graph. 

53 

54 Returns the main op including the group of ops that initializes all 

55 variables, initialize local variables, initialize all tables and the restore 

56 op name. 

57 

58 Args: 

59 restore_op_name: Name of the op to use to restore the graph. 

60 

61 Returns: 

62 The set of ops to be run as part of the main op upon the load operation. 

63 """ 

64 with ops.control_dependencies([main_op()]): 

65 main_op_with_restore = control_flow_ops.group(restore_op_name) 

66 return main_op_with_restore