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

3 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"""Loader functionality for SavedModel with hermetic, language-neutral exports. 

16 

17Load and restore capability for a SavedModel, which may include multiple meta 

18graph defs. Each SavedModel is associated with a single checkpoint. Each meta 

19graph def is saved with one or more tags, which are used to identify the exact 

20meta graph def to load. 

21 

22The `load` operation requires the session in which to restore the graph 

23definition and variables, the tags used to identify the meta graph def to 

24load and the location of the SavedModel. 

25 

26Upon a load, the subset of variables and assets supplied as part of the specific 

27meta graph def, will be restored into the supplied session. The values of the 

28variables though will correspond to the saved values from the first meta graph 

29added to the SavedModel using `add_meta_graph_and_variables(...)` in 

30`builder.py`. 

31 

32Typical usage: 

33 

34```python 

35... 

36builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir) 

37 

38with tf.compat.v1.Session(graph=tf.Graph()) as sess: 

39 ... 

40 builder.add_meta_graph_and_variables(sess, 

41 ["foo-tag"], 

42 signature_def_map=foo_signatures, 

43 assets_collection=foo_assets) 

44... 

45 

46with tf.compat.v1.Session(graph=tf.Graph()) as sess: 

47 ... 

48 builder.add_meta_graph(["bar-tag", "baz-tag"], 

49 assets_collection=bar_baz_assets) 

50... 

51 

52builder.save() 

53 

54... 

55with tf.compat.v1.Session(graph=tf.Graph()) as sess: 

56 tf.compat.v1.saved_model.loader.load(sess, ["foo-tag"], export_dir) 

57 ... 

58 

59``` 

60""" 

61 

62# pylint: disable=unused-import 

63from tensorflow.python.saved_model.loader_impl import load 

64from tensorflow.python.saved_model.loader_impl import maybe_saved_model_directory 

65# pylint: enable=unused-import