Assumes 'values_as_string' is a hex string that gets converted into a TF Lite DynamicBuffer. Strings are then extracted and copied into the TensorFlow tensor.
| 54 | // TF Lite DynamicBuffer. Strings are then extracted and copied into the |
| 55 | // TensorFlow tensor. |
| 56 | int FillTensorWithTfLiteHexString(tensorflow::Tensor* tensor, |
| 57 | const string& values_as_string) { |
| 58 | string s = absl::HexStringToBytes(values_as_string); |
| 59 | |
| 60 | int num_strings = values_as_string.empty() ? 0 : GetStringCount(s.data()); |
| 61 | |
| 62 | if (num_strings == tensor->NumElements()) { |
| 63 | auto data = tensor->flat<tensorflow::tstring>(); |
| 64 | for (size_t i = 0; i < num_strings; ++i) { |
| 65 | auto ref = GetString(s.data(), i); |
| 66 | data(i).assign(ref.str, ref.len); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return num_strings; |
| 71 | } |
| 72 | |
| 73 | template <typename T> |
| 74 | void FillTensorWithZeros(tensorflow::Tensor* tensor) { |
no test coverage detected