Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/util/keras_deps.py: 84%

32 statements  

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

1# Copyright 2020 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 

16"""Interface that provides access to Keras dependencies. 

17 

18This library is a common interface that contains Keras functions needed by 

19TensorFlow and TensorFlow Lite and is required as per the dependency inversion 

20principle (https://en.wikipedia.org/wiki/Dependency_inversion_principle). As per 

21this principle, high-level modules (eg: TensorFlow and TensorFlow Lite) should 

22not depend on low-level modules (eg: Keras) and instead both should depend on a 

23common interface such as this file. 

24""" 

25 

26 

27from tensorflow.python.util.tf_export import tf_export 

28 

29_KERAS_CALL_CONTEXT_FUNCTION = None 

30_KERAS_CLEAR_SESSION_FUNCTION = None 

31_KERAS_GET_SESSION_FUNCTION = None 

32_KERAS_LOAD_MODEL_FUNCTION = None 

33_KERAS_LOAD_CONTEXT_FUNCTION = None 

34 

35# TODO(b/169898786): Use the Keras public API when TFLite moves out of TF 

36 

37 

38# Register functions 

39@tf_export('__internal__.register_call_context_function', v1=[]) 

40def register_call_context_function(func): 

41 global _KERAS_CALL_CONTEXT_FUNCTION 

42 _KERAS_CALL_CONTEXT_FUNCTION = func 

43 

44 

45@tf_export('__internal__.register_clear_session_function', v1=[]) 

46def register_clear_session_function(func): 

47 global _KERAS_CLEAR_SESSION_FUNCTION 

48 _KERAS_CLEAR_SESSION_FUNCTION = func 

49 

50 

51@tf_export('__internal__.register_get_session_function', v1=[]) 

52def register_get_session_function(func): 

53 global _KERAS_GET_SESSION_FUNCTION 

54 _KERAS_GET_SESSION_FUNCTION = func 

55 

56 

57@tf_export('__internal__.register_load_model_function', v1=[]) 

58def register_load_model_function(func): 

59 global _KERAS_LOAD_MODEL_FUNCTION 

60 _KERAS_LOAD_MODEL_FUNCTION = func 

61 

62 

63# This is used to register the in_load_context function in 

64# third_party/py/keras/saving/saved_model/load_context.py for use in 

65# third_party/tensorflow library. 

66@tf_export('__internal__.register_load_context_function', v1=[]) 

67def register_load_context_function(func): 

68 global _KERAS_LOAD_CONTEXT_FUNCTION 

69 _KERAS_LOAD_CONTEXT_FUNCTION = func 

70 

71 

72# Get functions 

73def get_call_context_function(): 

74 global _KERAS_CALL_CONTEXT_FUNCTION 

75 return _KERAS_CALL_CONTEXT_FUNCTION 

76 

77 

78def get_clear_session_function(): 

79 global _KERAS_CLEAR_SESSION_FUNCTION 

80 return _KERAS_CLEAR_SESSION_FUNCTION 

81 

82 

83def get_get_session_function(): 

84 global _KERAS_GET_SESSION_FUNCTION 

85 return _KERAS_GET_SESSION_FUNCTION 

86 

87 

88def get_load_model_function(): 

89 global _KERAS_LOAD_MODEL_FUNCTION 

90 return _KERAS_LOAD_MODEL_FUNCTION 

91 

92 

93def get_load_context_function(): 

94 global _KERAS_LOAD_CONTEXT_FUNCTION # pylint: disable=global-variable-not-assigned 

95 return _KERAS_LOAD_CONTEXT_FUNCTION