Release 18.08
[platform/upstream/armnn.git] / tests / TfMobileNet-Armnn / TfMobileNet-Armnn.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
4 //
5 #include "../InferenceTest.hpp"
6 #include "../ImagePreprocessor.hpp"
7 #include "armnnTfParser/ITfParser.hpp"
8
9 int main(int argc, char* argv[])
10 {
11     int retVal = EXIT_FAILURE;
12     try
13     {
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},
18             // Top five predictions in tensorflow:
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},
26             // Top five predictions in tensorflow:
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},
34             // Top five predictions in tensorflow:
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         };
42
43         armnn::TensorShape inputTensorShape({ 1, 224, 224, 3  });
44
45         using DataType = float;
46         using DatabaseType = ImagePreprocessor<float>;
47         using ParserType = armnnTfParser::ITfParser;
48         using ModelType = InferenceModel<ParserType, DataType>;
49
50         // Coverity fix: ClassifierInferenceTestMain() may throw uncaught exceptions.
51         retVal = armnn::test::ClassifierInferenceTestMain<DatabaseType, ParserType>(
52                      argc, argv,
53                      "mobilenet_v1_1.0_224_fp32.pb", // model name
54                      true,                           // model is binary
55                      "input", "output",              // input and output tensor names
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(
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;
76 }