How to use diff_objects method in Kiwi

Best Python code snippet using Kiwi_python

detection_analyzer.py

Source:detection_analyzer.py Github

copy

Full Screen

1"""2Copyright (c) 2018-2021 Intel Corporation3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12"""13from collections import Counter14import numpy as np15from .base_data_analyzer import BaseDataAnalyzer16from ..logging import print_info17class DetectionDataAnalyzer(BaseDataAnalyzer):18 __provider__ = 'DetectionAnnotation'19 def analyze(self, result: list, meta, count_objects=True):20 data_analysis = {}21 counter = Counter()22 all_boxes = 023 diff_objects = 024 width = 025 height = 026 width_diff = 027 height_diff = 028 size = len(result)29 for data in result:30 all_boxes += data.size31 width += np.sum(data.x_maxs - data.x_mins)32 height += np.sum(data.y_maxs - data.y_mins)33 if 'difficult_boxes' in data.metadata:34 diff_objects += len(data.metadata['difficult_boxes'])35 for i in data.metadata['difficult_boxes']:36 width_diff += (data.x_maxs[i] - data.x_mins[i])37 height_diff += (data.y_maxs[i] - data.y_mins[i])38 counter.update(data.labels)39 if count_objects:40 data_analysis['annotations_size'] = self.object_count(result)41 print_info('Total boxes {}'.format(all_boxes))42 data_analysis['all_boxes'] = all_boxes43 label_map = meta.get('label_map', {})44 for key in counter:45 if key in label_map:46 print_info('{name}: {value}'.format(name=label_map[key], value=counter[key]))47 data_analysis[label_map[key]] = counter[key]48 else:49 print_info('class_{key}: {value}'.format(key=key, value=counter[key]))50 data_analysis['class_{}'.format(key)] = counter[key]51 if size > 0:52 avg_num_diff_objects = diff_objects/size53 avg_num_all_objects = all_boxes/size54 avg_width = width/all_boxes55 avg_height = height/all_boxes56 print_info(57 'Average number of difficult objects (boxes) per image: {average}'.format(average=avg_num_diff_objects)58 )59 print_info(60 'Average number of objects (boxes) per image: {average}'.format(average=avg_num_all_objects)61 )62 print_info(63 'Average size detection object: width: {width}, '64 'height: {height}'.format(width=avg_width, height=avg_height)65 )66 data_analysis['average_num_difficult_objects'] = avg_num_diff_objects67 data_analysis['average_num_all_objects'] = avg_num_all_objects68 data_analysis['average_width'] = avg_width69 data_analysis['average_height'] = avg_height70 if diff_objects > 0:71 avg_width_diff_objects = width_diff/diff_objects72 avg_height_diff_objects = height_diff / diff_objects73 print_info(74 'Average size difficult object: width: {width}, '75 'height: {height}\n'.format(width=avg_width_diff_objects, height=avg_height_diff_objects)76 )77 data_analysis['average_width_difficult_objects'] = avg_width_diff_objects78 data_analysis['average_height_difficult_objects'] = avg_height_diff_objects...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful