blob: e23dbdc9d499312eb51c3352b4ad0458749596ef [file] [log] [blame]
Nattapat Chaimanowongd8eee592018-10-26 10:24:14 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#include "../InferenceTest.hpp"
6#include "../ImagePreprocessor.hpp"
7#include "armnnTfLiteParser/ITfLiteParser.hpp"
8
9using namespace armnnTfLiteParser;
10
11int main(int argc, char* argv[])
12{
13 int retVal = EXIT_FAILURE;
14 try
15 {
16 // Coverity fix: The following code may throw an exception of type std::length_error.
17 std::vector<ImageSet> imageSet =
18 {
Matthew Bentham41d3fa62018-10-30 10:11:23 +000019 // The model we are using incorrectly classifies everything as class 699
20 // But can still be used for benchmarking the layers.
Nattapat Chaimanowongd8eee592018-10-26 10:24:14 +010021 {"Dog.jpg", 669},
22 {"Cat.jpg", 669},
23 {"shark.jpg", 669},
24 };
25
26 armnn::TensorShape inputTensorShape({ 2, 224, 224, 3 });
27
28 using DataType = uint8_t;
29 using DatabaseType = ImagePreprocessor<DataType>;
30 using ParserType = armnnTfLiteParser::ITfLiteParser;
31 using ModelType = InferenceModel<ParserType, DataType>;
32
33 // Coverity fix: ClassifierInferenceTestMain() may throw uncaught exceptions.
34 retVal = armnn::test::ClassifierInferenceTestMain<DatabaseType,
35 ParserType>(
36 argc, argv,
37 "vgg_16_u8.tflite", // model name
38 true, // model is binary
39 "content_vgg/concat", // input tensor name
40 "content_vgg/prob", // output tensor name
41 { 0, 1, 2 }, // test images to test with as above
42 [&imageSet](const char* dataDir, const ModelType & model) {
43 // we need to get the input quantization parameters from
44 // the parsed model
45 auto inputBinding = model.GetInputBindingInfo();
46 return DatabaseType(
47 dataDir,
48 224,
49 224,
50 imageSet,
51 inputBinding.second.GetQuantizationScale(),
52 inputBinding.second.GetQuantizationOffset(),
53 {{0, 0, 0}},
54 {{1, 1, 1}},
55 DatabaseType::DataFormat::NCHW,
56 2);
57 },
58 &inputTensorShape);
59 }
60 catch (const std::exception& e)
61 {
62 // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
63 // exception of type std::length_error.
64 // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
65 std::cerr << "WARNING: " << *argv << ": An error has occurred when running "
66 "the classifier inference tests: " << e.what() << std::endl;
67 }
68 return retVal;
69}