12 def __init__(self, modelPath, labelPath, backendId=0, targetId=0):
25 self.
_mean = np.array([0.485, 0.456, 0.406])[np.newaxis, np.newaxis, :]
26 self.
_std = np.array([0.229, 0.224, 0.225])[np.newaxis, np.newaxis, :]
31 def _load_labels(self):
35 labels.append(line.strip())
40 return self.__class__.__name__
50 def _preprocess(self, image):
51 image = image.astype(np.float32, copy=
False) / 255.0
54 return cv.dnn.blobFromImage(image)
57 assert image.shape[0] == self.
_inputSize[1],
'{} (height of input image) != {} (preset height)'.format(image.shape[0], self.
_inputSize[1])
58 assert image.shape[1] == self.
_inputSize[0],
'{} (width of input image) != {} (preset width)'.format(image.shape[1], self.
_inputSize[0])
72 def _postprocess(self, outputBlob):
73 class_id = np.argmax(outputBlob[0])