1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
12 #include <samples/common.hpp>
14 #include "inference_engine.hpp"
16 #include "samples/csv_dumper.hpp"
17 #include "image_decoder.hpp"
18 #include "samples/console_progress.hpp"
22 #define OUTPUT_FLOATING(val) std::fixed << std::setprecision(2) << val
26 struct InferenceMetrics {
28 double minDuration = std::numeric_limits<double>::max();
29 double maxDuration = 0;
32 virtual ~InferenceMetrics() { } // Type has to be polymorphic
36 std::string modelFileName;
37 std::string targetDevice;
38 std::string imagesPath;
40 InferenceEngine::InferRequest inferRequest;
41 InferenceEngine::InputsDataMap inputInfo;
42 InferenceEngine::OutputsDataMap outInfo;
43 InferenceEngine::CNNNetReader networkReader;
44 InferenceEngine::SizeVector inputDims;
45 InferenceEngine::SizeVector outputDims;
47 PreprocessingOptions preprocessingOptions;
50 InferencePlugin plugin;
54 double Infer(ConsoleProgress& progress, int filesWatched, InferenceMetrics& im);
57 Processor(const std::string& flags_m, const std::string& flags_d, const std::string& flags_i, int flags_b,
58 InferenceEngine::InferencePlugin plugin, CsvDumper& dumper, const std::string& approach, PreprocessingOptions preprocessingOptions);
60 virtual shared_ptr<InferenceMetrics> Process(bool stream_output = false) = 0;
61 virtual void Report(const InferenceMetrics& im) {
62 double averageTime = im.totalTime / im.nRuns;
64 slog::info << "Inference report:\n";
65 slog::info << "\tNetwork load time: " << loadDuration << "ms" << "\n";
66 slog::info << "\tModel: " << modelFileName << "\n";
67 slog::info << "\tModel Precision: " << networkReader.getNetwork().getPrecision().name() << "\n";
68 slog::info << "\tBatch size: " << batch << "\n";
69 slog::info << "\tValidation dataset: " << imagesPath << "\n";
70 slog::info << "\tValidation approach: " << approach;
71 slog::info << slog::endl;
74 slog::info << "Average infer time (ms): " << averageTime << " (" << OUTPUT_FLOATING(1000.0 / (averageTime / batch))
75 << " images per second with batch size = " << batch << ")" << slog::endl;
77 slog::warn << "No images processed" << slog::endl;
81 virtual ~Processor() {}