diff options
author | Jared Duke <jdduke@google.com> | 2018-09-07 11:01:45 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-07 11:07:26 -0700 |
commit | dfd6aba381a7867906ba2d173c1720bb38dec6a8 (patch) | |
tree | 03b2a8be78b4fee64c9090b9a7320ad0e1ec64ed /tensorflow/contrib/lite/experimental | |
parent | 19a015c8b6a56a588733bf98a37a1f63fcc7bca9 (diff) |
Add TFL_TensorName() to C API
PiperOrigin-RevId: 212002349
Diffstat (limited to 'tensorflow/contrib/lite/experimental')
-rw-r--r-- | tensorflow/contrib/lite/experimental/c/c_api.cc | 2 | ||||
-rw-r--r-- | tensorflow/contrib/lite/experimental/c/c_api.h | 10 | ||||
-rw-r--r-- | tensorflow/contrib/lite/experimental/c/c_api_test.cc | 4 |
3 files changed, 15 insertions, 1 deletions
diff --git a/tensorflow/contrib/lite/experimental/c/c_api.cc b/tensorflow/contrib/lite/experimental/c/c_api.cc index 0d852e72e6..c589cf71ea 100644 --- a/tensorflow/contrib/lite/experimental/c/c_api.cc +++ b/tensorflow/contrib/lite/experimental/c/c_api.cc @@ -133,6 +133,8 @@ void* TFL_TensorData(const TFL_Tensor* tensor) { return static_cast<void*>(tensor->data.raw); } +const char* TFL_TensorName(const TFL_Tensor* tensor) { return tensor->name; } + TFL_Status TFL_TensorCopyFromBuffer(TFL_Tensor* tensor, const void* input_data, size_t input_data_size) { if (tensor->bytes != input_data_size) { diff --git a/tensorflow/contrib/lite/experimental/c/c_api.h b/tensorflow/contrib/lite/experimental/c/c_api.h index 569d79d3d5..b429e76870 100644 --- a/tensorflow/contrib/lite/experimental/c/c_api.h +++ b/tensorflow/contrib/lite/experimental/c/c_api.h @@ -146,6 +146,11 @@ TFL_CAPI_EXPORT extern int32_t TFL_InterpreterGetOutputTensorCount( // Returns the tensor associated with the output index. // REQUIRES: 0 <= input_index < TFL_InterpreterGetOutputTensorCount(tensor) +// +// NOTE: The shape and underlying data buffer for output tensors may be not +// be available until after the output tensor has been both sized and allocated. +// In general, best practice is to interact with the output tensor *after* +// calling TFL_InterpreterInvoke(). TFL_CAPI_EXPORT extern const TFL_Tensor* TFL_InterpreterGetOutputTensor( const TFL_Interpreter* interpreter, int32_t output_index); @@ -173,12 +178,15 @@ TFL_CAPI_EXPORT extern size_t TFL_TensorByteSize(const TFL_Tensor* tensor); // Returns a pointer to the underlying data buffer. // -// Note: The result may be null if tensors have not yet been allocated, e.g., +// NOTE: The result may be null if tensors have not yet been allocated, e.g., // if the Tensor has just been created or resized and `TFL_AllocateTensors()` // has yet to be called, or if the output tensor is dynamically sized and the // interpreter hasn't been invoked. TFL_CAPI_EXPORT extern void* TFL_TensorData(const TFL_Tensor* tensor); +// Returns the (null-terminated) name of the tensor. +TFL_CAPI_EXPORT extern const char* TFL_TensorName(const TFL_Tensor* tensor); + // Copies from the provided input buffer into the tensor's buffer. // REQUIRES: input_data_size == TFL_TensorByteSize(tensor) TFL_CAPI_EXPORT extern TFL_Status TFL_TensorCopyFromBuffer( diff --git a/tensorflow/contrib/lite/experimental/c/c_api_test.cc b/tensorflow/contrib/lite/experimental/c/c_api_test.cc index a631dae890..649dac8d1a 100644 --- a/tensorflow/contrib/lite/experimental/c/c_api_test.cc +++ b/tensorflow/contrib/lite/experimental/c/c_api_test.cc @@ -55,6 +55,8 @@ TEST(CApiSimple, Smoke) { EXPECT_EQ(TFL_TensorNumDims(input_tensor), 1); EXPECT_EQ(TFL_TensorDim(input_tensor, 0), 2); EXPECT_EQ(TFL_TensorByteSize(input_tensor), sizeof(float) * 2); + EXPECT_NE(TFL_TensorData(input_tensor), nullptr); + EXPECT_STREQ(TFL_TensorName(input_tensor), "input"); std::array<float, 2> input = {1.f, 3.f}; ASSERT_EQ(TFL_TensorCopyFromBuffer(input_tensor, input.data(), @@ -70,6 +72,8 @@ TEST(CApiSimple, Smoke) { EXPECT_EQ(TFL_TensorNumDims(output_tensor), 1); EXPECT_EQ(TFL_TensorDim(output_tensor, 0), 2); EXPECT_EQ(TFL_TensorByteSize(output_tensor), sizeof(float) * 2); + EXPECT_NE(TFL_TensorData(output_tensor), nullptr); + EXPECT_STREQ(TFL_TensorName(output_tensor), "output"); std::array<float, 2> output; ASSERT_EQ(TFL_TensorCopyToBuffer(output_tensor, output.data(), |