blob: 44bbb709890a046fff489643ca7e1346d0a1c1dc [file] [log] [blame]
surmeh01bceff2f2018-03-29 16:29:27 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
surmeh01bceff2f2018-03-29 16:29:27 +01004//
5#include "../InferenceTest.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01006#include "../ImagePreprocessor.hpp"
surmeh01bceff2f2018-03-29 16:29:27 +01007#include "armnnTfParser/ITfParser.hpp"
8
9int main(int argc, char* argv[])
10{
surmeh013537c2c2018-05-18 16:31:43 +010011 int retVal = EXIT_FAILURE;
12 try
surmeh01bceff2f2018-03-29 16:29:27 +010013 {
surmeh013537c2c2018-05-18 16:31:43 +010014 // Coverity fix: The following code may throw an exception of type std::length_error.
15 std::vector<ImageSet> imageSet =
16 {
17 {"Dog.jpg", 209},
telsoa01c577f2c2018-08-31 09:22:23 +010018 // Top five predictions in tensorflow:
surmeh013537c2c2018-05-18 16:31:43 +010019 // -----------------------------------
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},
telsoa01c577f2c2018-08-31 09:22:23 +010026 // Top five predictions in tensorflow:
surmeh013537c2c2018-05-18 16:31:43 +010027 // -----------------------------------
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},
telsoa01c577f2c2018-08-31 09:22:23 +010034 // Top five predictions in tensorflow:
surmeh013537c2c2018-05-18 16:31:43 +010035 // -----------------------------------
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 };
surmeh01bceff2f2018-03-29 16:29:27 +010042
surmeh013537c2c2018-05-18 16:31:43 +010043 armnn::TensorShape inputTensorShape({ 1, 224, 224, 3 });
44
telsoa01c577f2c2018-08-31 09:22:23 +010045 using DataType = float;
46 using DatabaseType = ImagePreprocessor<float>;
47 using ParserType = armnnTfParser::ITfParser;
48 using ModelType = InferenceModel<ParserType, DataType>;
49
surmeh013537c2c2018-05-18 16:31:43 +010050 // Coverity fix: ClassifierInferenceTestMain() may throw uncaught exceptions.
telsoa01c577f2c2018-08-31 09:22:23 +010051 retVal = armnn::test::ClassifierInferenceTestMain<DatabaseType, ParserType>(
52 argc, argv,
surmeh0157f1e202018-09-05 17:09:22 +010053 "mobilenet_v1_1.0_224_frozen.pb", // model name
telsoa01c577f2c2018-08-31 09:22:23 +010054 true, // model is binary
surmeh0157f1e202018-09-05 17:09:22 +010055 "input", "MobilenetV1/Predictions/Reshape_1", // input and output tensor names
telsoa01c577f2c2018-08-31 09:22:23 +010056 { 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(
surmeh013537c2c2018-05-18 16:31:43 +010060 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;
surmeh01bceff2f2018-03-29 16:29:27 +010076}