488 ParseArgs progArgs = ParseArgs(argc, argv);
493 if (!progArgs.dynamicBackendPath.empty())
495 std::cout <<
"Loading backends from" << progArgs.dynamicBackendPath <<
"\n";
499 auto runtime = IRuntime::Create(runtimeOptions);
502 ARMNN_LOG(fatal) <<
"Could not create runtime.";
508 auto parser = ITfLiteParser::Create(parserOptions);
511 ARMNN_LOG(info) <<
"Loading backbone...";
513 const DumpToDot dumpToDot = progArgs.dumpToDot;
518 progArgs.prefBackendsBackbone,
521 auto inputId = parser->GetNetworkInputBindingInfo(0,
"inputs");
522 auto bbOut0Id = parser->GetNetworkOutputBindingInfo(0,
"input_to_detector_1");
523 auto bbOut1Id = parser->GetNetworkOutputBindingInfo(0,
"input_to_detector_2");
524 auto bbOut2Id = parser->GetNetworkOutputBindingInfo(0,
"input_to_detector_3");
525 auto backboneProfile = runtime->GetProfiler(backboneId);
526 backboneProfile->EnableProfiling(
true);
530 ARMNN_LOG(info) <<
"Loading detector...";
536 progArgs.prefBackendsDetector,
539 auto detectIn0Id = parser->GetNetworkInputBindingInfo(0,
"input_to_detector_1");
540 auto detectIn1Id = parser->GetNetworkInputBindingInfo(0,
"input_to_detector_2");
541 auto detectIn2Id = parser->GetNetworkInputBindingInfo(0,
"input_to_detector_3");
542 auto outputBoxesId = parser->GetNetworkOutputBindingInfo(0,
"output_boxes");
543 auto detectorProfile = runtime->GetProfiler(detectorId);
546 ARMNN_LOG(info) <<
"Loading test image...";
547 auto image =
LoadImage(progArgs.imageDir.c_str());
550 return LOAD_IMAGE_ERROR;
554 std::vector<float> intermediateMem0(bbOut0Id.second.GetNumElements());
555 std::vector<float> intermediateMem1(bbOut1Id.second.GetNumElements());
556 std::vector<float> intermediateMem2(bbOut2Id.second.GetNumElements());
557 std::vector<float> intermediateMem3(outputBoxesId.second.GetNumElements());
560 using BindingInfos = std::vector<armnn::BindingPointInfo>;
561 using FloatTensors = std::vector<std::reference_wrapper<std::vector<float>>>;
564 FloatTensors{ image });
566 FloatTensors{ intermediateMem0,
572 FloatTensors{ intermediateMem0,
576 FloatTensors{ intermediateMem3 });
578 static const int numIterations=2;
579 using DurationUS = std::chrono::duration<double, std::micro>;
580 std::vector<DurationUS> nmsDurations(0);
581 std::vector<yolov3::Detection> filtered_boxes;
582 nmsDurations.reserve(numIterations);
583 for (
int i=0; i < numIterations; i++)
586 ARMNN_LOG(info) <<
"Running backbone...";
587 runtime->EnqueueWorkload(backboneId, bbInputTensors, bbOutputTensors);
590 ARMNN_LOG(info) <<
"Running detector...";
591 runtime->EnqueueWorkload(detectorId, detectInputTensors, detectOutputTensors);
595 using clock = std::chrono::steady_clock;
596 auto nmsStartTime = clock::now();
602 filtered_boxes =
yolov3::nms(config, intermediateMem3);
603 auto nmsEndTime = clock::now();
610 const auto nmsDuration = DurationUS(nmsStartTime - nmsEndTime);
611 nmsDurations.push_back(nmsDuration);
613 backboneProfile->EnableProfiling(
true);
614 detectorProfile->EnableProfiling(
true);
617 std::ofstream backboneProfileStream(
"backbone.json");
618 backboneProfile->Print(backboneProfileStream);
619 backboneProfileStream.close();
621 std::ofstream detectorProfileStream(
"detector.json");
622 detectorProfile->Print(detectorProfileStream);
623 detectorProfileStream.close();
626 std::ofstream nmsProfileStream(
"nms.json");
627 nmsProfileStream <<
"{" <<
"\n";
628 nmsProfileStream << R
"( "NmsTimings": {)" << "\n";
629 nmsProfileStream << R
"( "raw": [)" << "\n";
631 for (
auto duration : nmsDurations)
635 nmsProfileStream <<
",\n";
638 nmsProfileStream <<
" " << duration.count();
641 nmsProfileStream <<
"\n";
642 nmsProfileStream << R
"( "units": "us")" << "\n";
643 nmsProfileStream <<
" ]" <<
"\n";
644 nmsProfileStream <<
" }" <<
"\n";
645 nmsProfileStream <<
"}" <<
"\n";
646 nmsProfileStream.close();
648 if (progArgs.comparisonFiles.size() > 0)
655 progArgs.comparisonFiles);
void CheckAccuracy(std::vector< float > *toDetector0, std::vector< float > *toDetector1, std::vector< float > *toDetector2, std::vector< float > *detectorOutput, const std::vector< yolov3::Detection > &nmsOut, const std::vector< std::string > &filePaths)
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
int LoadModel(const char *filename, ITfLiteParser &parser, IRuntime &runtime, NetworkId &networkId, const std::vector< BackendId > &backendPreferences, ImportMemory enableImport, DumpToDot dumpToDot)
armnn::InputTensors MakeInputTensors(const std::vector< armnn::BindingPointInfo > &inputBindings, const std::vector< std::reference_wrapper< TContainer >> &inputDataContainers)
#define ARMNN_LOG(severity)
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
unsigned int num_boxes
Number of detected boxes.
std::vector< float > LoadImage(const char *filename)
void SetLogFilter(LogSeverity level)
void print_detection(std::ostream &os, const std::vector< Detection > &detections)
Print identified yolo detections.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
float iou_threshold
Inclusion threshold for Intersection-Over-Union.
std::string m_DynamicBackendsPath
Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive Only a...
std::vector< Detection > nms(const NMSConfig &config, const std::vector< float > &detected_boxes)
Perform Non-Maxima Supression on a list of given detections.
armnn::OutputTensors MakeOutputTensors(const std::vector< armnn::BindingPointInfo > &outputBindings, const std::vector< std::reference_wrapper< TContainer >> &outputDataContainers)
Non Maxima Suprresion configuration meta-data.
float confidence_threshold
Inclusion confidence threshold for a box.
unsigned int num_classes
Number of classes in the detected boxes.