Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctness checking for security_barrier_camera_demo w/ 1 network multi channels with inputting 1 image #3392

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8f579f2
Add some debug info in security_barrier_camera_demo.
yangwang201911 Jan 24, 2022
fef9a0a
Update.
yangwang201911 Mar 7, 2022
d101b67
Update the debug msg and Add result paser for security_barrier_camera…
yangwang201911 Mar 10, 2022
7d5ff26
Add correctness checker interface for demo.
yangwang201911 Mar 10, 2022
3551ada
Implement parser and correcteness checker for security_barrier_camera…
yangwang201911 Mar 14, 2022
3fb15e0
Add correctness checker script and instantiate checker of demo securi…
yangwang201911 Mar 16, 2022
6fb10ef
. exit when task list is empty and inputs source is image instead of …
yangwang201911 Mar 22, 2022
7eca858
Exit worker thread when the inferences of all frames have been comple…
yangwang201911 Mar 23, 2022
a2f8421
Update parameters of demo security_barrier_camera_demo so that just i…
yangwang201911 Mar 23, 2022
b0845bc
Merge branch 'master' into ywang2/analysis_result_automatically_for_A…
yangwang201911 Mar 23, 2022
cc86f1d
Add the comment of replacing model for the demo security_barrier_cam…
yangwang201911 Mar 23, 2022
37f8371
Input single image for demo security_barrier_camera_demo.
yangwang201911 Mar 23, 2022
237dcf3
Update.
yangwang201911 Mar 23, 2022
d0e831b
Update.
yangwang201911 Mar 23, 2022
6b9ce5a
Update.
yangwang201911 Mar 25, 2022
85327ef
Decouple of the raw data saving from the run_tests.py.
yangwang201911 Mar 25, 2022
ab9d19c
Update.
yangwang201911 Mar 28, 2022
f1c5c87
Add scope 'correctness' to enable correctness checking.
yangwang201911 Mar 31, 2022
b4d110b
Remove the log save for each demo and update the correctness checker.
yangwang201911 Apr 1, 2022
dbe9f13
Update.
yangwang201911 Apr 1, 2022
065ca07
Update format and remove some redundant code.
yangwang201911 Apr 1, 2022
3755135
Update.
yangwang201911 Apr 1, 2022
603c120
Revert the common thread.
yangwang201911 Apr 2, 2022
2e2ade4
Update.
yangwang201911 Apr 6, 2022
3596cd2
Merge branch 'master' into ywang2/analysis_result_automatically_for_A…
yangwang201911 Apr 6, 2022
a3e464a
Update correctness checker as the common measure for all demos.
yangwang201911 Apr 7, 2022
8631f93
1. Fix the issue that demo lost the inference of the last frame when …
yangwang201911 Apr 8, 2022
91baf7d
Updata correctness checker and revert inputing images hanlder for se…
yangwang201911 Apr 11, 2022
2fe3933
1. Update correctness checker to support the multi models inputting. …
yangwang201911 Apr 12, 2022
128ec7e
Merge branch 'master' into ywang2/analysis_result_automatically_for_A…
yangwang201911 Apr 12, 2022
0914845
Update exit code when correctness checking falied.
yangwang201911 Apr 13, 2022
796e315
Modify the input dataset path when updating option '-i' for demo.
yangwang201911 Apr 15, 2022
f33983d
Update correctness checker.
yangwang201911 Apr 15, 2022
7c47ce7
Correct the output layer order of the attributes model for the securi…
yangwang201911 Apr 24, 2022
2f066d1
1. Stop reborning if images frame ID is invalid. 2. clone image frame…
yangwang201911 Apr 26, 2022
1562b9b
Update correctness checking logic.
yangwang201911 Apr 28, 2022
d2d37e3
1. fix the bug in the security demo that lost the results of the infe…
yangwang201911 May 5, 2022
65fe33b
1. Throw the exception when parsing raw data failed. 2. Correct the v…
yangwang201911 May 6, 2022
1f44622
Add logic to check if the size of vehicle attributs is correct.
yangwang201911 May 7, 2022
0ff6d8c
Update correctness checking.
yangwang201911 May 9, 2022
3958ea4
Fix the hang issue when inputting images folder.
yangwang201911 May 23, 2022
42171be
Update correctness checking logic to handle the exception.
yangwang201911 May 25, 2022
ba629d0
Update.
yangwang201911 May 25, 2022
6c43933
Fix hange issue when inputting images folder.
yangwang201911 May 26, 2022
c10b3ce
Merge branch 'master' of https://github.com/openvinotoolkit/open_mode…
yangwang201911 Jun 24, 2022
5ccace4
Fix the run_tests.py terminated with exception when timeout occurs.
yangwang201911 Jun 28, 2022
a5d84dc
Update.
yangwang201911 Aug 15, 2022
77968e6
Merge branch 'master' into ywang2/analysis_result_automatically_for_A…
yangwang201911 Aug 15, 2022
7c57fd2
update.
yangwang201911 Aug 16, 2022
f7d7a1d
Update.
yangwang201911 Sep 13, 2022
bb8e615
Merge branch 'ywang2/fix_run_tests_terminated_with_exception_when_tim…
yangwang201911 Sep 13, 2022
19f9ff1
Update.
yangwang201911 Sep 13, 2022
8739a29
Merge branch 'ywang2/fix_run_tests_terminated_with_exception_when_tim…
yangwang201911 Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion demos/common/cpp/utils/include/utils/threads_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class Worker {
}
}
void stop() {
running = false;
if (tasks.empty())
running = false;
tasksCondVar.notify_all();
}
void join() {
Expand Down
2 changes: 1 addition & 1 deletion demos/common/cpp/utils/src/args_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ std::vector<std::string> parseDevices(const std::string& device_string) {
const std::string::size_type colon_position = device_string.find(":");
if (colon_position != std::string::npos) {
std::string device_type = device_string.substr(0, colon_position);
if (device_type == "HETERO" || device_type == "MULTI") {
if (device_type == "HETERO" || device_type == "MULTI" || device_type == "AUTO") {
std::string comma_separated_devices = device_string.substr(colon_position + 1);
std::vector<std::string> devices = split(comma_separated_devices, ',');
for (auto& device : devices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

log.basicConfig(format='[ %(levelname)s ] %(message)s', level=log.DEBUG, stream=sys.stdout)

DEVICE_KINDS = ['CPU', 'GPU', 'MYRIAD', 'HETERO', 'HDDL']
DEVICE_KINDS = ['CPU', 'GPU', 'AUTO', 'AUTO:CPU,GPU', 'MULTI:CPU,GPU', 'MYRIAD', 'HETERO', 'HDDL']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be required for security_barrier_camera_demo ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update



def build_argparser():
Expand Down
17 changes: 12 additions & 5 deletions demos/security_barrier_camera_demo/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class ClassifiersAggregator {
std::mutex& printMutex = static_cast<ReborningVideoFrame*>(sharedVideoFrame.get())->context.classifiersAggregatorPrintMutex;
printMutex.lock();
if (FLAGS_r && !rawDetections.empty()) {
slog::debug << "Frame #: " << sharedVideoFrame->frameId << slog::endl;
slog::debug << rawDetections;
for (const std::string& rawDetection : rawDetections)
slog::debug << rawDetection << slog::endl;
// destructor assures that none uses the container
for (const std::string& rawAttribute : rawAttributes.container) {
slog::debug << rawAttribute << slog::endl;
Expand Down Expand Up @@ -292,6 +292,10 @@ ReborningVideoFrame::~ReborningVideoFrame() {
context.videoFramesContext.lastFrameIdsMutexes[sourceID].lock();
const auto frameId = ++context.videoFramesContext.lastframeIds[sourceID];
context.videoFramesContext.lastFrameIdsMutexes[sourceID].unlock();

// Stop reborning when frame ID reached to input queue size
if (!context.isVideo && frameId >= FLAGS_n_iqs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It just decreases the actual queue size

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It just decreases the actual queue size

From my understanding, the number of frames passing through each channel will be specified by FLGAS_n_iqs. This code just ensure stopping reborning new frame when frame ID reached to FLAGS_n_iqs.

return;
std::shared_ptr<ReborningVideoFrame> reborn = std::make_shared<ReborningVideoFrame>(context, sourceID, frameId, frame);
worker->push(std::make_shared<Reader>(reborn));
} catch (const std::bad_weak_ptr&) {}
Expand Down Expand Up @@ -379,7 +383,9 @@ void Drawer::process() {
} else {
if (!context.isVideo) {
try {
std::shared_ptr<Worker>(context.drawersContext.drawersWorker)->stop();
// Exit only when inferences on all of frames are finished.
if (context.frameCounter >= FLAGS_n_iqs * context.readersContext.inputChannels.size())
std::shared_ptr<Worker>(context.drawersContext.drawersWorker)->stop();
}
catch (const std::bad_weak_ptr&) {}
}
Expand Down Expand Up @@ -428,7 +434,8 @@ bool DetectionsProcessor::isReady() {
if (requireGettingNumberOfDetections) {
classifiersAggregator = std::make_shared<ClassifiersAggregator>(sharedVideoFrame);
std::list<Detector::Result> results;
results = context.inferTasksContext.detector.getResults(*inferRequest, sharedVideoFrame->frame.size(), classifiersAggregator->rawDetections);
results = context.inferTasksContext.detector.getResults(*inferRequest, sharedVideoFrame->sourceID, sharedVideoFrame->frameId, sharedVideoFrame->frame.size(), classifiersAggregator->rawDetections);

for (Detector::Result result : results) {
switch (result.label) {
case 1:
Expand Down Expand Up @@ -585,7 +592,6 @@ void InferTask::process() {
std::reference_wrapper<ov::InferRequest> inferRequest = detectorsInfers.inferRequests.container.back();
detectorsInfers.inferRequests.container.pop_back();
detectorsInfers.inferRequests.mutex.unlock();

context.inferTasksContext.detector.setImage(inferRequest, sharedVideoFrame->frame);

inferRequest.get().set_callback(
Expand All @@ -607,6 +613,7 @@ void InferTask::process() {
bool Reader::isReady() {
Context& context = static_cast<ReborningVideoFrame*>(sharedVideoFrame.get())->context;
context.readersContext.lastCapturedFrameIdsMutexes[sharedVideoFrame->sourceID].lock();
// Look for the next frame
if (context.readersContext.lastCapturedFrameIds[sharedVideoFrame->sourceID] + 1 == sharedVideoFrame->frameId) {
return true;
} else {
Expand Down
10 changes: 5 additions & 5 deletions demos/security_barrier_camera_demo/cpp/net_wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ class Detector {
}
}

std::list<Result> getResults(ov::InferRequest& inferRequest, cv::Size upscale, std::vector<std::string>& rawResults) {
// there is no big difference if InferReq of detector from another device is passed
// because the processing is the same for the same topology
std::list<Result> getResults(ov::InferRequest& inferRequest, const int64_t channelID, const int64_t frameID, cv::Size upscale, std::vector<std::string>& rawResults) {
// there is no big difference if InferReq of detector from another device is passed because the processing is the same for the same topology
std::list<Result> results;
ov::Tensor output_tensor = inferRequest.get_tensor(m_detectorOutputName);
const float* const detections = output_tensor.data<float>();
Expand All @@ -146,8 +145,9 @@ class Detector {
rect.height = static_cast<int>(detections[i * objectSize + 6] * upscale.height) - rect.y;
results.push_back(Result{label, confidence, rect});
std::ostringstream rawResultsStream;
rawResultsStream << "[" << i << "," << label << "] element, prob = " << confidence
<< " (" << rect.x << "," << rect.y << ")-(" << rect.width << "," << rect.height << ")";
rawResultsStream << "ChannelId:" << channelID << ",FrameId:" << frameID << ",";
rawResultsStream << "ObjId:" << i << "," << label << "," << confidence
<< "," << rect.x << "," << rect.y << "," << rect.width << "," << rect.height;
rawResults.push_back(rawResultsStream.str());
}
return results;
Expand Down
5 changes: 3 additions & 2 deletions demos/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,11 @@ def single_option_cases(key, *args):
model_keys=['-m', '-m_lpr', '-m_va'],
device_keys=['-d', '-d_lpr', '-d_va'],
test_cases=combine_cases(
TestCase(options={'-no_show': None,
TestCase(options={'-no_show': None, '-r' : None, '-n_iqs': '1',
anzhella-pankratova marked this conversation as resolved.
Show resolved Hide resolved
**MONITORS,
'-i': DataDirectoryArg('vehicle-license-plate-detection-barrier')}),
TestCase(options={'-m': ModelArg('vehicle-license-plate-detection-barrier-0106')}),
# Change the model in order to obtain the ROI data
TestCase(options={'-m': ModelArg('vehicle-license-plate-detection-barrier-0123')}),
single_option_cases('-m_lpr',
None,
ModelArg('license-plate-recognition-barrier-0001'),
Expand Down
135 changes: 135 additions & 0 deletions demos/tests/correctness_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env python3

# Copyright (c) 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABC, abstractmethod
from unittest import case

class Demo(ABC):
def __init__(self, name, implementation):
self.name = name
self.implementation = implementation
self.subdirectory = name + '/' + implementation
self.results = {}

@abstractmethod
def parser(self):
pass

@abstractmethod
def checker(self):
pass

class CPPDemo(Demo):
def __init__(self, name, implementation='cpp'):
super().__init__(name, implementation)
self.results = {}
pass

def parser(self):
fo = None
try:
fo = open('/tmp/' + self.subdirectory + '/results.log', 'r')
except IOError as err:
print("File error: " + str(err))
output = [i.rstrip() for i in fo.readlines()]
device = ''
case_index = ''
index = 1
while index < len(output):
if "Device" in output[index]:
device = output[index][output[index].find(":") + 1:]
if device not in self.results:
self.results[device] = {}

if "CaseId" in output[index]:
case_index = output[index][output[index].find(":") + 1:]
if case_index not in self.results[device]:
self.results[device][case_index] = {}

if "Execution_time" in output[index]:
execution_time = output[index].split(':')[1]
if execution_time == '-1':
while index < len(output) and 'Device' not in output[index]:
index += 1
continue

# Pase the raw data
while index < len(output) and 'ChannelId' in output[index]:
item = output[index][output[index].find('ChannelId'):].split(',')
# Channel ID
frame_results = {}
channel = item[0].split(':')
if channel[1] not in self.results[device][case_index]:
self.results[device][case_index][channel[1]] = frame_results

# Frame ID
object_results = {}
frame = item[1].split(':')
if frame[1] not in self.results[device][case_index][channel[1]]:
self.results[device][case_index][channel[1]][frame[1]] = object_results

# Object ID
label_prob_pos_results = []
objid = item[2].split(':')
if objid[1] not in self.results[device][case_index][channel[1]][frame[1]]:
self.results[device][case_index][channel[1]][frame[1]][objid[1]] = label_prob_pos_results
self.results[device][case_index][channel[1]][frame[1]][objid[1]] = item[3:]
index += 1

index += 1


def checker(self):
self.parser()
anzhella-pankratova marked this conversation as resolved.
Show resolved Hide resolved

flag = False
if "CPU" in self.results and "AUTO:CPU" in self.results:
if self.results['CPU'] == self.results['AUTO:CPU']:
flag = True
else:
print ("CPU vs AUTO:CPU have inconsistent results")

if "GPU" in self.results and "AUTO:GPU" in self.results:
if self.results['GPU'] == self.results['AUTO:GPU']:
flag = True
else:
print ("GPU vs AUTO:GPU have inconsistent results")

if not flag:
for device in self.results:
for case in self.results[device]:
print ("---* Device: {} - Case: {} *----\n".format(device, case))
for channel in self.results[device][case]:
print ("Channel: {} - :{}".format(channel, self.results[device][case][channel]))
print ('---------------------------------------------------------')
return flag



DEMOS = [
CPPDemo(name='security_barrier_camera_demo')
]
def main():
anzhella-pankratova marked this conversation as resolved.
Show resolved Hide resolved
for demo in DEMOS:
print ("Checking {}...".format(demo.name))
if demo.checker():
print("Demo: {} passed.".format(demo.name))
else:
print("Demo: {} failed.".format(demo.name))
anzhella-pankratova marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == '__main__':
main()
26 changes: 22 additions & 4 deletions demos/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import contextlib
import csv
import json
from operator import contains
import os
import shlex
import subprocess # nosec - disable B404:import-subprocess check
Expand Down Expand Up @@ -261,7 +262,12 @@ def main():
print(header)
print()
demo.set_precisions(args.precisions, model_info)

filename = '/tmp/' + demo.subdirectory
anzhella-pankratova marked this conversation as resolved.
Show resolved Hide resolved
os.makedirs(filename, exist_ok=True)
fo = open(filename + '/results.log', 'w+')
print("Save to {}".format(filename))
content = ''
content += 'Testing {}...'.format(demo.subdirectory) + '\n'
declared_model_names = set()
for model_data in json.loads(subprocess.check_output(
[sys.executable, '--', str(auto_tools_dir / 'info_dumper.py'),
Expand Down Expand Up @@ -325,13 +331,20 @@ def option_to_args(key, value):
for arg in fixed_args + dev_arg + case_args))
print(test_descr)
print(flush=True)
content += "Device:{}\nCaseId:{}\n".format(device, test_case_index)
rawResults = ''
execution_time = -1
try:
start_time = timeit.default_timer()
output = subprocess.check_output(fixed_args + dev_arg + case_args,
stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf-8',
env=demo_environment, timeout=600)
execution_time = timeit.default_timer() - start_time
demo.parse_output(output, test_case, device)
for line in output.split('\n'):
if "DEBUG" in line:
rawResults += line
rawResults += '\n'
demo.parse_output(output, device, test_case_index)
anzhella-pankratova marked this conversation as resolved.
Show resolved Hide resolved
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
output = e.output
if isinstance(e, subprocess.CalledProcessError):
Expand All @@ -343,15 +356,20 @@ def option_to_args(key, value):
failed_tests.append(test_descr + '\n' + exit_msg)
num_failures += 1
execution_time = -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore it


rawResults = {}

content += "Execution_time:{}\n".format(execution_time)
content += "{}\n".format(rawResults)
fo.write(content)
content = ''
if args.report_file:
collect_result(demo.subdirectory, device, case_model_names, execution_time, args.report_file)
if args.log_file:
if test_case_index == 0:
write_log(header, args.log_file)
write_log(test_descr, args.log_file)
write_log(output, args.log_file)

fo.close()
print()

print("{} failures:".format(num_failures))
Expand Down