aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/c/checkpoint_reader.cc
diff options
context:
space:
mode:
authorGravatar Zongheng Yang <zongheng@google.com>2016-10-07 11:16:41 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-10-07 12:33:03 -0700
commitcae3713cd4a2a191f10012a8efab19c721d41742 (patch)
treecdbff4a58a3a76977a9696ff8ef816ca8200bd10 /tensorflow/c/checkpoint_reader.cc
parent2c2f81afec9cf992272fd22a6bb493b33b994800 (diff)
tensor_bundle: tighten Lookup() semantics, add LookupDtypeShape().
This fixes a subtle allocation issue in CheckpointReader. Change: 135503615
Diffstat (limited to 'tensorflow/c/checkpoint_reader.cc')
-rw-r--r--tensorflow/c/checkpoint_reader.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/tensorflow/c/checkpoint_reader.cc b/tensorflow/c/checkpoint_reader.cc
index 23a42cffbb..2ac3f75e5b 100644
--- a/tensorflow/c/checkpoint_reader.cc
+++ b/tensorflow/c/checkpoint_reader.cc
@@ -81,9 +81,14 @@ void CheckpointReader::GetTensor(
if (reader_ != nullptr) {
status = reader_->GetTensor(name, out_tensor);
} else {
- std::unique_ptr<Tensor> tensor(new Tensor);
- status = v2_reader_->Lookup(name, tensor.get());
- if (status.ok()) std::swap(*out_tensor, tensor);
+ tensorflow::DataType dtype;
+ tensorflow::TensorShape shape;
+ status = v2_reader_->LookupDtypeAndShape(name, &dtype, &shape);
+ if (status.ok()) {
+ out_tensor->reset(new Tensor(dtype, shape));
+ status = v2_reader_->Lookup(name, out_tensor->get());
+ if (!status.ok()) out_tensor->reset();
+ }
}
if (!status.ok()) {
Set_TF_Status_from_Status(out_status, status);