Hello everyone!
I am trying to modify the TensorFlow source code in order to add decryption functionality that will decrypt the encrypted saved_model.pb and its associated files (such as variables.data-00000-of-00001 and variables.index) and load them into memory without saving them back to disk. This process depends on the return value of the decryption function, which determines whether the content is loaded from a string or a stream.
I have successfully implemented this functionality for the saved_model.pb file by modifying mainly this file. However, I have been facing challenges in implementing it for the variables files. I am currently confused about how the variables are read in the code.
It seems that the processing of variables occurs in this section of the code (link):
const string variables_directory =
io::JoinPath(export_dir, kSavedModelVariablesDirectory);
// 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));
TF_ASSIGN_OR_RETURN(
bool variables_index_exists,
internal::FileExists(Env::Default(), variables_index_path));
if (!variables_index_exists) {
LOG(INFO) << "The specified SavedModel has no variables; no checkpoints "
"were restored. File does not exist: "
<< variables_index_path;
return OkStatus();
}
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<tstring>()() = variables_path;
std::vector<std::pair<string, Tensor>> inputs = {
{string(variable_filename_const_op_name), variables_path_tensor}};
AddAssetsTensorsToInputs(export_dir, asset_file_defs, &inputs);
RunMetadata run_metadata;
return RunOnce(run_options, inputs, {}, {string(restore_op_name)},
nullptr /* outputs */, &run_metadata, session);
When I inspect the value of variables_path_tensor, it only shows ./variables/variables as the path, which is the prefix and not the full path (e.g., ./variables/variables.data-00000-of-00001).
Now, I am uncertain whether what I am trying to achieve is even possible. If anyone can suggest a way to store the content of the variable file in a variable (after decrypting the file) and pass it to the rest of the code, I would greatly appreciate it. Since I am also new to C++.
Those are the locations where the varibales are proccessed I think: 1 → 2 → 3 → 4
Thanks a lot in advance.
Mo