Detect objects in an image with an Artificial Neural Network.
Module sppas.src.imgdata
Class NeuralNetCaffeDetector
Description
Constructor
View Source
def __init__(self):
super(NeuralNetCaffeDetector, self).__init__()
self._extension = '.caffemodel'
Private functions
_set_detector
Initialize the model with the given file.
Parameters
- model: (str) Filename of the Caffe model file
Raises
IOError, Exception
View Source
def _set_detector(self, model):
"""Initialize the model with the given file.
:param model: (str) Filename of the Caffe model file
:raise: IOError, Exception
"""
fn, fe = os.path.splitext(model)
proto = fn + '.prototxt'
if os.path.exists(proto) is False:
raise sppasIOError(proto)
try:
self._detector = cv2.dnn.readNetFromCaffe(proto, model)
except cv2.error as e:
logging.error('Artificial Neural Network model or proto (Caffe) failed to be read.')
raise sppasError(str(e))
_net_detections
Initialize net and blob for the processing.
Returns
- detections.
Parameters
- image
View Source
def _net_detections(self, image):
"""Initialize net and blob for the processing.
:returns: detections.
"""
img = image.iresize(width=0, height=360)
w, h = img.size()
blob = cv2.dnn.blobFromImage(img, 1.0, (w, h), (103.93, 116.77, 123.68))
self._detector.setInput(blob)
return self._detector.forward()