JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
base_metric.py
Go to the documentation of this file.
1import cv2 as cv
2
3from ..timer import Timer
4
6 def __init__(self, **kwargs):
7 self._warmup = kwargs.pop('warmup', 3)
8 self._repeat = kwargs.pop('repeat', 10)
9 self._reduction = kwargs.pop('reduction', 'median')
10
11 self._timer = Timer()
12
13 def _calcMedian(self, records):
14 ''' Return the median of records
15 '''
16 l = len(records)
17 mid = int(l / 2)
18 if l % 2 == 0:
19 return (records[mid] + records[mid - 1]) / 2
20 else:
21 return records[mid]
22
23 def _calcGMean(self, records, drop_largest=3):
24 ''' Return the geometric mean of records after drop the first drop_largest
25 '''
26 l = len(records)
27 if l <= drop_largest:
28 print('len(records)({}) <= drop_largest({}), stop dropping.'.format(l, drop_largest))
29 records_sorted = sorted(records, reverse=True)
30 return sum(records_sorted[drop_largest:]) / (l - drop_largest)
31
32 def _getResult(self):
33 records = self._timer.getRecords()
34 if self._reduction == 'median':
35 return self._calcMedian(records)
36 elif self._reduction == 'gmean':
37 return self._calcGMean(records)
38 else:
39 raise NotImplementedError('Reduction {} is not supported'.format(self._reduction))
40
41 def getReduction(self):
42 return self._reduction
43
44 def forward(self, model, *args, **kwargs):
45 raise NotImplementedError('Not implemented')
forward(self, model, *args, **kwargs)
_calcGMean(self, records, drop_largest=3)