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

28 statements  

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

1# Copyright 2022 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"""Path helpers utility functions.""" 

17 

18from tensorflow.python.lib.io import file_io 

19from tensorflow.python.saved_model import constants 

20from tensorflow.python.util import compat 

21 

22 

23def get_or_create_variables_dir(export_dir): 

24 """Return variables sub-directory, or create one if it doesn't exist.""" 

25 variables_dir = get_variables_dir(export_dir) 

26 file_io.recursive_create_dir(variables_dir) 

27 return variables_dir 

28 

29 

30def get_variables_dir(export_dir): 

31 """Return variables sub-directory in the SavedModel.""" 

32 return file_io.join( 

33 compat.as_text(export_dir), compat.as_text(constants.VARIABLES_DIRECTORY)) 

34 

35 

36def get_variables_path(export_dir): 

37 """Return the variables path, used as the prefix for checkpoint files.""" 

38 return file_io.join( 

39 compat.as_text(get_variables_dir(export_dir)), 

40 compat.as_text(constants.VARIABLES_FILENAME)) 

41 

42 

43def get_or_create_assets_dir(export_dir): 

44 """Return assets sub-directory, or create one if it doesn't exist.""" 

45 assets_destination_dir = get_assets_dir(export_dir) 

46 

47 file_io.recursive_create_dir(assets_destination_dir) 

48 

49 return assets_destination_dir 

50 

51 

52def get_assets_dir(export_dir): 

53 """Return path to asset directory in the SavedModel.""" 

54 return file_io.join( 

55 compat.as_text(export_dir), compat.as_text(constants.ASSETS_DIRECTORY)) 

56 

57 

58def get_or_create_debug_dir(export_dir): 

59 """Returns path to the debug sub-directory, creating if it does not exist.""" 

60 debug_dir = get_debug_dir(export_dir) 

61 

62 file_io.recursive_create_dir(debug_dir) 

63 

64 return debug_dir 

65 

66 

67def get_saved_model_pbtxt_path(export_dir): 

68 return file_io.join( 

69 compat.as_bytes(compat.path_to_str(export_dir)), 

70 compat.as_bytes(constants.SAVED_MODEL_FILENAME_PBTXT)) 

71 

72 

73def get_saved_model_pb_path(export_dir): 

74 return file_io.join( 

75 compat.as_bytes(compat.path_to_str(export_dir)), 

76 compat.as_bytes(constants.SAVED_MODEL_FILENAME_PB)) 

77 

78 

79def get_debug_dir(export_dir): 

80 """Returns path to the debug sub-directory in the SavedModel.""" 

81 return file_io.join( 

82 compat.as_text(export_dir), compat.as_text(constants.DEBUG_DIRECTORY))