surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 4 | // |
| 5 | #include "../InferenceTest.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 6 | #include "../ImagePreprocessor.hpp" |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 7 | #include "armnnTfParser/ITfParser.hpp" |
| 8 | |
| 9 | int main(int argc, char* argv[]) |
| 10 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 11 | int retVal = EXIT_FAILURE; |
| 12 | try |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 13 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 14 | // Coverity fix: The following code may throw an exception of type std::length_error. |
| 15 | std::vector<ImageSet> imageSet = |
| 16 | { |
| 17 | {"Dog.jpg", 209}, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | // Top five predictions in tensorflow: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 19 | // ----------------------------------- |
| 20 | // 209:Labrador retriever 0.949995 |
| 21 | // 160:Rhodesian ridgeback 0.0270182 |
| 22 | // 208:golden retriever 0.0192866 |
| 23 | // 853:tennis ball 0.000470382 |
| 24 | // 239:Greater Swiss Mountain dog 0.000464451 |
| 25 | {"Cat.jpg", 283}, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 26 | // Top five predictions in tensorflow: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 27 | // ----------------------------------- |
| 28 | // 283:tiger cat 0.579016 |
| 29 | // 286:Egyptian cat 0.319676 |
| 30 | // 282:tabby, tabby cat 0.0873346 |
| 31 | // 288:lynx, catamount 0.011163 |
| 32 | // 289:leopard, Panthera pardus 0.000856755 |
| 33 | {"shark.jpg", 3}, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 34 | // Top five predictions in tensorflow: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 35 | // ----------------------------------- |
| 36 | // 3:great white shark, white shark, ... 0.996926 |
| 37 | // 4:tiger shark, Galeocerdo cuvieri 0.00270528 |
| 38 | // 149:killer whale, killer, orca, ... 0.000121848 |
| 39 | // 395:sturgeon 7.78977e-05 |
| 40 | // 5:hammerhead, hammerhead shark 6.44127e-055 |
| 41 | }; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 42 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 43 | armnn::TensorShape inputTensorShape({ 1, 224, 224, 3 }); |
| 44 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | using DataType = float; |
| 46 | using DatabaseType = ImagePreprocessor<float>; |
| 47 | using ParserType = armnnTfParser::ITfParser; |
| 48 | using ModelType = InferenceModel<ParserType, DataType>; |
| 49 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 50 | // Coverity fix: ClassifierInferenceTestMain() may throw uncaught exceptions. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 51 | retVal = armnn::test::ClassifierInferenceTestMain<DatabaseType, ParserType>( |
| 52 | argc, argv, |
surmeh01 | 57f1e20 | 2018-09-05 17:09:22 +0100 | [diff] [blame^] | 53 | "mobilenet_v1_1.0_224_frozen.pb", // model name |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 54 | true, // model is binary |
surmeh01 | 57f1e20 | 2018-09-05 17:09:22 +0100 | [diff] [blame^] | 55 | "input", "MobilenetV1/Predictions/Reshape_1", // input and output tensor names |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 56 | { 0, 1, 2 }, // test images to test with as above |
| 57 | [&imageSet](const char* dataDir, const ModelType&) { |
| 58 | // This creates a 224x224x3 NHWC float tensor to pass to Armnn |
| 59 | return DatabaseType( |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 60 | dataDir, |
| 61 | 224, |
| 62 | 224, |
| 63 | imageSet); |
| 64 | }, |
| 65 | &inputTensorShape); |
| 66 | } |
| 67 | catch (const std::exception& e) |
| 68 | { |
| 69 | // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an |
| 70 | // exception of type std::length_error. |
| 71 | // Using stderr instead in this context as there is no point in nesting try-catch blocks here. |
| 72 | std::cerr << "WARNING: TfMobileNet-Armnn: An error has occurred when running " |
| 73 | "the classifier inference tests: " << e.what() << std::endl; |
| 74 | } |
| 75 | return retVal; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 76 | } |