test_tflite_model_executor.cc 930 B

123456789101112131415161718192021222324252627
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/optimization_guide/core/test_tflite_model_executor.h"
  5. #include "third_party/tflite_support/src/tensorflow_lite_support/cc/task/core/task_utils.h"
  6. namespace optimization_guide {
  7. bool TestTFLiteModelExecutor::Preprocess(
  8. const std::vector<TfLiteTensor*>& input_tensors,
  9. const std::vector<float>& input) {
  10. return tflite::task::core::PopulateTensor<float>(input, input_tensors[0])
  11. .ok();
  12. }
  13. absl::optional<std::vector<float>> TestTFLiteModelExecutor::Postprocess(
  14. const std::vector<const TfLiteTensor*>& output_tensors) {
  15. std::vector<float> data;
  16. absl::Status status =
  17. tflite::task::core::PopulateVector<float>(output_tensors[0], &data);
  18. DCHECK(status.ok());
  19. return data;
  20. }
  21. } // namespace optimization_guide