From 4e118daa4a04807806baf4008a508cb316d5c7c1 Mon Sep 17 00:00:00 2001 From: Sukriti Ramesh Date: Tue, 18 Oct 2016 09:11:23 -0800 Subject: [PATCH] Switch to Saver v2 checkpoint in SavedModel. Change: 136486667 --- tensorflow/cc/saved_model/BUILD | 1 + tensorflow/cc/saved_model/constants.h | 4 ---- tensorflow/cc/saved_model/loader.cc | 22 +++++++++++------- .../testdata/half_plus_two/saved_model.pb | Bin 5501 -> 6491 bytes .../half_plus_two/variables/variables | Bin 169 -> 0 bytes .../variables/variables.data-00000-of-00001 | Bin 0 -> 8 bytes .../half_plus_two/variables/variables.index | Bin 0 -> 134 bytes .../variables/variables-00000-of-00001 | Bin 169 -> 0 bytes .../variables/variables.data-00000-of-00001 | Bin 0 -> 8 bytes .../variables/variables.index | Bin 0 -> 134 bytes .../half_plus_two_sharded/saved_model.pb | Bin 5501 -> 6491 bytes .../variables/variables-00000-of-00001 | Bin 169 -> 0 bytes .../variables/variables.data-00000-of-00001 | Bin 0 -> 8 bytes .../variables/variables.index | Bin 0 -> 134 bytes .../saved_model_half_plus_two/saved_model.pb | Bin 5501 -> 6491 bytes .../variables/checkpoint | 2 -- .../variables/variables-00000-of-00001 | Bin 169 -> 0 bytes .../variables/variables.data-00000-of-00001 | Bin 0 -> 8 bytes .../variables/variables.index | Bin 0 -> 134 bytes tensorflow/python/saved_model/builder.py | 4 ++-- tensorflow/python/saved_model/constants.py | 1 - .../example/saved_model_half_plus_two.py | 4 ++-- tensorflow/python/saved_model/loader.py | 2 +- 23 files changed, 19 insertions(+), 21 deletions(-) delete mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two/variables/variables create mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two/variables/variables.data-00000-of-00001 create mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two/variables/variables.index delete mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two_pbtxt/variables/variables-00000-of-00001 create mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two_pbtxt/variables/variables.data-00000-of-00001 create mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two_pbtxt/variables/variables.index delete mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two_sharded/variables/variables-00000-of-00001 create mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two_sharded/variables/variables.data-00000-of-00001 create mode 100644 tensorflow/cc/saved_model/testdata/half_plus_two_sharded/variables/variables.index delete mode 100644 tensorflow/contrib/session_bundle/testdata/saved_model_half_plus_two/variables/checkpoint delete mode 100644 tensorflow/contrib/session_bundle/testdata/saved_model_half_plus_two/variables/variables-00000-of-00001 create mode 100644 tensorflow/contrib/session_bundle/testdata/saved_model_half_plus_two/variables/variables.data-00000-of-00001 create mode 100644 tensorflow/contrib/session_bundle/testdata/saved_model_half_plus_two/variables/variables.index diff --git a/tensorflow/cc/saved_model/BUILD b/tensorflow/cc/saved_model/BUILD index bb2a6063b5c..6a55ecf9369 100644 --- a/tensorflow/cc/saved_model/BUILD +++ b/tensorflow/cc/saved_model/BUILD @@ -31,6 +31,7 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", "//tensorflow/core:tensorflow", + "//tensorflow/core/util/tensor_bundle:naming", ], ) diff --git a/tensorflow/cc/saved_model/constants.h b/tensorflow/cc/saved_model/constants.h index b97f6c84faf..61ffa7a09ac 100644 --- a/tensorflow/cc/saved_model/constants.h +++ b/tensorflow/cc/saved_model/constants.h @@ -36,10 +36,6 @@ constexpr char kSavedModelVariablesDirectory[] = "variables"; // SavedModel variables filename. constexpr char kSavedModelVariablesFilename[] = "variables"; -// SavedModel sharded variables filename. -constexpr char kSavedModelVariablesShardedFilename[] = - "variables-\?\?\?\?\?-of-\?\?\?\?\?"; - // Commonly used tags. constexpr char kSavedModelTagServe[] = "serve"; constexpr char kSavedModelTagTrain[] = "train"; diff --git a/tensorflow/cc/saved_model/loader.cc b/tensorflow/cc/saved_model/loader.cc index 329bea48fa8..1f952293550 100644 --- a/tensorflow/cc/saved_model/loader.cc +++ b/tensorflow/cc/saved_model/loader.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/protobuf/saved_model.pb.h" #include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session_options.h" +#include "tensorflow/core/util/tensor_bundle/naming.h" namespace tensorflow { namespace { @@ -87,17 +88,20 @@ Status Restore(const RunOptions& run_options, const string& export_dir, const StringPiece variable_filename_const_op_name, Session* session) { // Find path to variables to be restored in export directory. - string variables_path = + const string variables_directory = io::JoinPath(export_dir, kSavedModelVariablesDirectory); - const string unsharded_variables_path = - io::JoinPath(variables_path, kSavedModelVariablesFilename); - if (Env::Default()->FileExists(unsharded_variables_path)) { - variables_path = unsharded_variables_path; - } else { - const string sharded_variables_path = - io::JoinPath(variables_path, kSavedModelVariablesShardedFilename); - variables_path = sharded_variables_path; + // Check for saver checkpoints in v2 format. Models exported in the checkpoint + // v2 format will have a variables.index file. The corresponding + // variables are stored in the variables.data-?????-of-????? files. + const string variables_index_path = io::JoinPath( + variables_directory, MetaFilename(kSavedModelVariablesFilename)); + if (!Env::Default()->FileExists(variables_index_path)) { + return errors::NotFound( + "Checkpoint index file not found in SavedModel directory."); } + const string variables_path = + io::JoinPath(variables_directory, kSavedModelVariablesFilename); + // Add variables to the graph. Tensor variables_path_tensor(DT_STRING, TensorShape({})); variables_path_tensor.scalar()() = variables_path; diff --git a/tensorflow/cc/saved_model/testdata/half_plus_two/saved_model.pb b/tensorflow/cc/saved_model/testdata/half_plus_two/saved_model.pb index d0f0853aa879e0eacd316bb84827512d2101e9b5..e894f9b1011fc66b81877f06944d23e517ee1953 100644 GIT binary patch delta 1431 zcmb7EO>Y}T7|v|g-sIibj)#1hZ5t|=L)ZwfKU%k@y^zpWEvf-EDiRW`HoIeI)%DJ@ zGY$z=6(R8l&|G=|{zJ)$0}|rUYkNXS{SllwfS4WIsnfJV+;%?peLmjznZNDlO>++6 z-<$A@iI2?3=6U4r0KP-gKDpQ2+9m$|goZI^cop98kC$$el3ut^SjE6A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