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 25 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
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
15 changes: 11 additions & 4 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
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
7 changes: 6 additions & 1 deletion demos/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def parse_output(self, output, test_case, device):
if self.parser:
self.parser(output, test_case, device)

def check_difference(self):
if self.parser:
return self.parser.check_difference()

def update_option(self, updated_options):
for case in self.test_cases[:]:
self.update_case(case, updated_options, with_replacement=True)
Expand Down Expand Up @@ -602,7 +606,8 @@ def single_option_cases(key, *args):
TestCase(options={'-no_show': None,
**MONITORS,
'-i': DataDirectoryArg('vehicle-license-plate-detection-barrier')}),
TestCase(options={'-m': ModelArg('vehicle-license-plate-detection-barrier-0106')}),
# Update to this 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
140 changes: 140 additions & 0 deletions demos/tests/correctness_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# 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.

import os
from copy import deepcopy
from abc import ABC, abstractmethod

from cases import BASE

class CorrectnessCheckerBase(ABC):
def __init__(self, demo):
self.filename = demo.subdirectory.replace('/', '_') + '.log'
self.demo_name = demo.subdirectory.split('/')[0]
self.results = {}
self.case_index = {}

@abstractmethod
def __call__(self, output, test_case, device, execution_time=-1):
pass

@abstractmethod
def check_difference(self):
pass

def write_to_log(self, result, test_case, device):
with open(self.filename, 'w') as f:
print(self.results, file=f)


class DemoSecurityBarrierCamera(CorrectnessCheckerBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this class should not be one demo specific

Suggested change
class DemoSecurityBarrierCamera(CorrectnessCheckerBase):
class MultiChannelCorrectness(CorrectnessCheckerBase):

Copy link
Author

@yangwang201911 yangwang201911 Apr 6, 2022

Choose a reason for hiding this comment

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

there are different parsing or correctness checking implement for the different demos. I think it's better to implement the parser and checker within each demo

def __call__(self, output, test_case, device, execution_time=0):
# Results format
# {"device name":
# {"case index 0":
# {"channel id 0":
# {"frame id 0":
# {"object id 0":{"label:xx,prob:xx,x,y,width,hight"},
# {"object id 1":{"label:xx,prob:xx,x,y,width,hight"},
# .....................
# {"object id n":{"label:xx,prob:xx,x,y,width,hight"}
# },
# .....
# {"frame id n":
# .....
# }
# },
# .....
# {"channel id n":
# .....
# }
# {"case index n":
# .....
# }
# }

# Generate case id for each device
if device not in self.case_index:
self.case_index[device] = 0

if device not in self.results:
self.results[device] = {}

case_index = self.case_index[device]
if case_index not in self.results[device]:
self.results[device][case_index] = {}

# Parsing the raw data
output = [i.rstrip() for i in output.split('\n') if "DEBUG" in i and "ChannelId" in i]
for item in output:
item = item[item.find('ChannelId'):].split(',')
# Channel ID
frame_results = {}
channel = item[0].split(':')[1]
if channel not in self.results[device][case_index]:
self.results[device][case_index][channel] = frame_results

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

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

self.case_index[device] += 1

def check_difference(self):
flag = True
devices_list = {"AUTO:GPU,CPU" : ["CPU", "GPU"],
"AUTO:CPU" : ["CPU"],
"AUTO:GPU" : ["GPU"],
"MULTI:GPU,CPU" : ["CPU", "GPU"]}
err_msg = ''
for device in devices_list:
for target in devices_list[device]:
if device not in self.results or target not in self.results:
flag = False
err_msg += "\tMiss the results of device {} or device {}.\n".format(device, target)
if device in self.results and target in self.results:
if self.results[device] != self.results[target]:
flag = False
err_msg += "\tInconsistent results between device {} and {} \n".format(device, target)
# Show the detailed inconsistent results
for case in self.results[target]:
if self.results[device][case] != self.results[target][case]:
err_msg += ("\t\t---* Device: {} - Case: {} *----\n".format(device, case))
for channel in self.results[device][case]:
for frame in self.results[device][case][channel]:
err_msg += ("\t\t\tChannel {} - Frame {} : {}\n".format(channel, frame, self.results[device][case][channel][frame]))
err_msg += ('\t\t---------------------------------------------------------\n')
err_msg += ("\t\t---* Device: {} - Case: {} *----\n".format(target, case))
for channel in self.results[target][case]:
for frame in self.results[target][case][channel]:
err_msg += ("\t\t\tChannel {} - Frame {} : {}\n".format(channel, frame, self.results[target][case][channel][frame]))
err_msg += ('\t\t---------------------------------------------------------\n')
if not flag:
print("Correctness checking: Failure\n{}".format(err_msg))
return flag

DEMOS = [
BASE['security_barrier_camera_demo/cpp']
.update_option({'-r': None, '-n_iqs': '1'})
.add_parser(DemoSecurityBarrierCamera)
]
14 changes: 9 additions & 5 deletions demos/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
scopes = {
'base': importlib.import_module('cases').DEMOS,
'performance': importlib.import_module('performance_cases').DEMOS,
'correctness': importlib.import_module('correctness_cases').DEMOS,
}


Expand All @@ -71,7 +72,7 @@ def parse_args():
help='list of demos to run tests for (by default, every demo is tested). '
'For testing demos of specific implementation pass one (or more) of the next values: cpp, cpp_gapi, python.')
parser.add_argument('--scope', default='base',
help='The scenario for testing demos.', choices=('base', 'performance'))
help='The scenario for testing demos.', choices=('base', 'performance', 'correctness'))
parser.add_argument('--mo', type=Path, metavar='MO.PY',
help='Model Optimizer entry point script')
parser.add_argument('--devices', default="CPU GPU",
Expand Down Expand Up @@ -243,6 +244,7 @@ def main():
dl_dir = prepare_models(auto_tools_dir, args.downloader_cache_dir, args.mo, global_temp_dir, demos_to_test, args.precisions)

num_failures = 0
correctness_failures = 0

try:
pythonpath = f"{os.environ['PYTHONPATH']}{os.pathsep}"
Expand All @@ -261,7 +263,6 @@ def main():
print(header)
print()
demo.set_precisions(args.precisions, model_info)

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 @@ -342,7 +343,6 @@ def option_to_args(key, value):
print(output)
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


if args.report_file:
collect_result(demo.subdirectory, device, case_model_names, execution_time, args.report_file)
Expand All @@ -351,9 +351,13 @@ def option_to_args(key, value):
write_log(header, args.log_file)
write_log(test_descr, args.log_file)
write_log(output, args.log_file)

if args.scope == "correctness":
print("Demo {} correctness checking....".format(demo.subdirectory))
if not demo.check_difference():
correctness_failures += 1
print()

if args.scope == "correctness":
print("Correctness Failures: {}".format(correctness_failures))
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be printed before print("{} failures:".format(num_failures))

print("{} failures:".format(num_failures))
for test in failed_tests:
print(test)
Expand Down