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 | // ----------------------------------- |
surmeh01 | c3b012e | 2018-09-12 16:00:26 +0100 | [diff] [blame] | 20 | // 209:Labrador retriever 0.46392533 |
| 21 | // 160:Rhodesian ridgeback 0.29911423 |
| 22 | // 208:golden retriever 0.108059585 |
| 23 | // 169:redbone 0.033753652 |
| 24 | // 274:dingo, warrigal, warragal, ... 0.01232666 |
| 25 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 26 | {"Cat.jpg", 283}, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | // Top five predictions in tensorflow: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 28 | // ----------------------------------- |
surmeh01 | c3b012e | 2018-09-12 16:00:26 +0100 | [diff] [blame] | 29 | // 283:tiger cat 0.6508582 |
| 30 | // 286:Egyptian cat 0.2604343 |
| 31 | // 282:tabby, tabby cat 0.028786005 |
| 32 | // 288:lynx, catamount 0.020673484 |
| 33 | // 40:common iguana, iguana, ... 0.0080499435 |
| 34 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 35 | {"shark.jpg", 3}, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 36 | // Top five predictions in tensorflow: |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 37 | // ----------------------------------- |
surmeh01 | c3b012e | 2018-09-12 16:00:26 +0100 | [diff] [blame] | 38 | // 3:great white shark, white shark, ... 0.96672016 |
| 39 | // 4:tiger shark, Galeocerdo cuvieri 0.028302953 |
| 40 | // 149:killer whale, killer, orca, ... 0.0020228163 |
| 41 | // 5:hammerhead, hammerhead shark 0.0017547971 |
| 42 | // 150:dugong, Dugong dugon 0.0003968083 |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 43 | }; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 44 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 45 | armnn::TensorShape inputTensorShape({ 1, 224, 224, 3 }); |
| 46 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 47 | using DataType = float; |
| 48 | using DatabaseType = ImagePreprocessor<float>; |
| 49 | using ParserType = armnnTfParser::ITfParser; |
| 50 | using ModelType = InferenceModel<ParserType, DataType>; |
| 51 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 52 | // Coverity fix: ClassifierInferenceTestMain() may throw uncaught exceptions. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 53 | retVal = armnn::test::ClassifierInferenceTestMain<DatabaseType, ParserType>( |
| 54 | argc, argv, |
surmeh01 | c3b012e | 2018-09-12 16:00:26 +0100 | [diff] [blame] | 55 | "mobilenet_v1_1.0_224_frozen.pb", // model name |
| 56 | true, // model is binary |
| 57 | "input", "MobilenetV1/Predictions/Reshape_1", // input and output tensor names |
| 58 | { 0, 1, 2 }, // test images to test with as above |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 59 | [&imageSet](const char* dataDir, const ModelType&) { |
| 60 | // This creates a 224x224x3 NHWC float tensor to pass to Armnn |
| 61 | return DatabaseType( |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 62 | dataDir, |
| 63 | 224, |
| 64 | 224, |
| 65 | imageSet); |
| 66 | }, |
| 67 | &inputTensorShape); |
| 68 | } |
| 69 | catch (const std::exception& e) |
| 70 | { |
| 71 | // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an |
| 72 | // exception of type std::length_error. |
| 73 | // Using stderr instead in this context as there is no point in nesting try-catch blocks here. |
| 74 | std::cerr << "WARNING: TfMobileNet-Armnn: An error has occurred when running " |
| 75 | "the classifier inference tests: " << e.what() << std::endl; |
| 76 | } |
| 77 | return retVal; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 78 | } |