-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Changes from 25 commits
8f579f2
fef9a0a
d101b67
7d5ff26
3551ada
3fb15e0
6fb10ef
7eca858
a2f8421
b0845bc
cc86f1d
37f8371
237dcf3
d0e831b
6b9ce5a
85327ef
ab9d19c
f1c5c87
b4d110b
dbe9f13
065ca07
3755135
603c120
2e2ade4
3596cd2
a3e464a
8631f93
91baf7d
2fe3933
128ec7e
0914845
796e315
f33983d
7c47ce7
2f066d1
1562b9b
d2d37e3
65fe33b
1f44622
0ff6d8c
3958ea4
42171be
ba629d0
6c43933
c10b3ce
5ccace4
a5d84dc
77968e6
7c57fd2
f7d7a1d
bb8e615
19f9ff1
8739a29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this class should not be one demo specific
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
} | ||
|
||
|
||
|
@@ -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", | ||
|
@@ -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}" | ||
|
@@ -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'), | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be printed before |
||
print("{} failures:".format(num_failures)) | ||
for test in failed_tests: | ||
print(test) | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 toFLAGS_n_iqs
.