blob: 1313d2d01afe26a6b9d0ea0ff60a0aa11be81cbb [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 {
19 // Class number in probability print out offset by 1000 due to batch size fix
20 {"Dog.jpg", 669},
21 {"Cat.jpg", 669},
22 {"shark.jpg", 669},
23 };
24
25 armnn::TensorShape inputTensorShape({ 2, 224, 224, 3 });
26
27 using DataType = uint8_t;
28 using DatabaseType = ImagePreprocessor<DataType>;
29 using ParserType = armnnTfLiteParser::ITfLiteParser;
30 using ModelType = InferenceModel<ParserType, DataType>;
31
32 // Coverity fix: ClassifierInferenceTestMain() may throw uncaught exceptions.
33 retVal = armnn::test::ClassifierInferenceTestMain<DatabaseType,
34 ParserType>(
35 argc, argv,
36 "vgg_16_u8.tflite", // model name
37 true, // model is binary
38 "content_vgg/concat", // input tensor name
39 "content_vgg/prob", // output tensor name
40 { 0, 1, 2 }, // test images to test with as above
41 [&imageSet](const char* dataDir, const ModelType & model) {
42 // we need to get the input quantization parameters from
43 // the parsed model
44 auto inputBinding = model.GetInputBindingInfo();
45 return DatabaseType(
46 dataDir,
47 224,
48 224,
49 imageSet,
50 inputBinding.second.GetQuantizationScale(),
51 inputBinding.second.GetQuantizationOffset(),
52 {{0, 0, 0}},
53 {{1, 1, 1}},
54 DatabaseType::DataFormat::NCHW,
55 2);
56 },
57 &inputTensorShape);
58 }
59 catch (const std::exception& e)
60 {
61 // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
62 // exception of type std::length_error.
63 // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
64 std::cerr << "WARNING: " << *argv << ": An error has occurred when running "
65 "the classifier inference tests: " << e.what() << std::endl;
66 }
67 return retVal;
68}