Home | History | Annotate | Download | only in testing
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 #ifndef TENSORFLOW_CONTRIB_LITE_NNAPI_PARSE_TESTDATA_H_
     16 #define TENSORFLOW_CONTRIB_LITE_NNAPI_PARSE_TESTDATA_H_
     17 
     18 #include <vector>
     19 #include "tensorflow/contrib/lite/interpreter.h"
     20 #include "tensorflow/contrib/lite/testing/test_runner.h"
     21 
     22 namespace tflite {
     23 namespace testing {
     24 
     25 // Shape and data for a float tensor
     26 struct FloatTensor {
     27   std::vector<int> shape;
     28   std::vector<float> flat_data;
     29 };
     30 
     31 // A prescribed input, output example
     32 struct Example {
     33   std::vector<FloatTensor> inputs;
     34   std::vector<FloatTensor> outputs;
     35 };
     36 
     37 // Parses an example input and output file (used for unit tests)
     38 TfLiteStatus ParseExamples(const char* filename,
     39                            std::vector<Example>* examples);
     40 
     41 // Inputs Tensors into a TensorFlow lite interpreter. Note, this will run
     42 // interpreter.AllocateTensors();
     43 TfLiteStatus FeedExample(tflite::Interpreter* interpreter, const Example&);
     44 
     45 // Check outputs against (already) evaluated result.
     46 TfLiteStatus CheckOutputs(tflite::Interpreter* interpreter, const Example&);
     47 
     48 // Parses a test description and feeds the given test runner with data.
     49 // The input format is similar to an ASCII proto:
     50 //   // Loads model 'add.bin' from the TestRunner's model directory.
     51 //   load_model: "add.bin"
     52 //   // Changes the shape of inputs, provided in the same order they appear
     53 //   // in the model.
     54 //   reshape {
     55 //     input: "1,224,224,3"
     56 //     input: "1,3,4,1"
     57 //   }
     58 //   // Fills the given persistent tensors with zeros.
     59 //   init_state: 0,1,2,3
     60 //   // Invokes the interpreter with the given input and checks that it
     61 //   // produces the expected output. Inputs and outputs should be specified in
     62 //   // the order they appear in the model.
     63 //   invoke {
     64 //     input: "1,2,3,4,56"
     65 //     input: "0.1,0.2,0.3,4.3,56.4"
     66 //     output: "12,3,4,545,3"
     67 //     output: "0.01,0.02"
     68 //   }
     69 bool ParseAndRunTests(std::istream* input, TestRunner* test_runner);
     70 
     71 }  // namespace testing
     72 }  // namespace tflite
     73 
     74 #endif  // TENSORFLOW_CONTRIB_LITE_NNAPI_PARSE_TESTDATA_H_
     75