Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 1 | // |
| 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 | |
| 9 | using namespace armnnTfLiteParser; |
| 10 | |
| 11 | int 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 | { |
FinnWilliamsArm | edb8b2e | 2019-05-29 13:42:37 +0100 | [diff] [blame] | 19 | // The model we are using incorrectly classifies the images |
Matthew Bentham | 41d3fa6 | 2018-10-30 10:11:23 +0000 | [diff] [blame] | 20 | // But can still be used for benchmarking the layers. |
FinnWilliamsArm | edb8b2e | 2019-05-29 13:42:37 +0100 | [diff] [blame] | 21 | {"Dog.jpg", 178}, |
| 22 | {"Cat.jpg", 39}, |
| 23 | {"shark.jpg", 598}, |
Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 26 | armnn::TensorShape inputTensorShape({ 1, 224, 224, 3 }); |
Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 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, |
David Monahan | dc27979 | 2019-04-23 10:54:34 +0100 | [diff] [blame] | 37 | "vgg_16_int8.tflite", // model name |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 38 | true, // model is binary |
David Monahan | dc27979 | 2019-04-23 10:54:34 +0100 | [diff] [blame] | 39 | "input", // input tensor name |
| 40 | "vgg_16/fc8/squeezed", // output tensor name |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 41 | { 0, 1, 2 }, // test images to test with as above |
Derek Lamberti | eb1fce0 | 2019-12-10 21:20:10 +0000 | [diff] [blame] | 42 | [&imageSet](const char* dataDir, const ModelType &) { |
Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 43 | // we need to get the input quantization parameters from |
| 44 | // the parsed model |
Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 45 | return DatabaseType( |
| 46 | dataDir, |
| 47 | 224, |
| 48 | 224, |
| 49 | imageSet, |
FinnWilliamsArm | af8b72d | 2019-05-22 14:50:55 +0100 | [diff] [blame] | 50 | 1, |
Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 51 | {{0, 0, 0}}, |
| 52 | {{1, 1, 1}}, |
| 53 | DatabaseType::DataFormat::NCHW, |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 54 | 1); |
Nattapat Chaimanowong | d8eee59 | 2018-10-26 10:24:14 +0100 | [diff] [blame] | 55 | }, |
| 56 | &inputTensorShape); |
| 57 | } |
| 58 | catch (const std::exception& e) |
| 59 | { |
| 60 | // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an |
| 61 | // exception of type std::length_error. |
| 62 | // Using stderr instead in this context as there is no point in nesting try-catch blocks here. |
| 63 | std::cerr << "WARNING: " << *argv << ": An error has occurred when running " |
| 64 | "the classifier inference tests: " << e.what() << std::endl; |
| 65 | } |
| 66 | return retVal; |
| 67 | } |