MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ImportTensorData

Function ImportTensorData

tensorflow/lite/toco/import_tensorflow.cc:324–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322
323template <typename T>
324tensorflow::Status ImportTensorData(const TensorProto& input_tensor,
325 int input_flat_size,
326 std::vector<T>* output_data) {
327 CHECK_GE(output_data->size(), input_flat_size);
328 int num_elements_in_tensor = TensorTraits<T>::size(input_tensor);
329 if (num_elements_in_tensor == input_flat_size) {
330 for (int i = 0; i < num_elements_in_tensor; i++) {
331 (*output_data)[i] = TensorTraits<T>::get(input_tensor, i);
332 }
333 } else if (input_tensor.tensor_content().size() ==
334 input_flat_size * sizeof(T)) {
335 TensorTraits<T>::CopyFromContent(input_tensor, output_data);
336 } else if (num_elements_in_tensor > 0 &&
337 num_elements_in_tensor < input_flat_size) {
338 // TODO(b/80208043): use tensorflow::Tensor::FromProto() which is the
339 // official way to import tensor data. This particular else-if handles a
340 // grappler optimization where the last few elements in a tensor are
341 // omitted if they are repeated.
342 int i = 0;
343 for (; i < num_elements_in_tensor; ++i) {
344 (*output_data)[i] = TensorTraits<T>::get(input_tensor, i);
345 }
346 auto last = (*output_data)[i - 1];
347 for (; i < input_flat_size; ++i) {
348 (*output_data)[i] = last;
349 }
350 } else {
351 string accessor_name = TensorTraits<T>::accessor_name();
352 string type_name = TensorTraits<T>::type_name();
353 return tensorflow::errors::InvalidArgument(
354 absl::StrCat("Neither input_content (",
355 input_tensor.tensor_content().size() / sizeof(T), ") nor ",
356 accessor_name, " (", num_elements_in_tensor,
357 ") have the right dimensions (", input_flat_size,
358 ") for this ", type_name, " tensor"));
359 }
360 return tensorflow::Status::OK();
361}
362
363tensorflow::Status ImportFloatArray(const TensorProto& input_tensor,
364 Array* output_array) {

Callers

nothing calls this directly

Calls 5

InvalidArgumentFunction · 0.85
sizeFunction · 0.50
getFunction · 0.50
StrCatFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected