SPPAS 4.22

https://sppas.org/

Module sppas.src.imgdata

Class NeuralNetTensorFlowDetector

Description

Detect objects in an image with an Artificial Neural Network.

Constructor

View Source
def __init__(self):
    super(NeuralNetTensorFlowDetector, self).__init__()
    self._extension = '.pb'

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 + '.pbtxt'
    if os.path.exists(proto) is False:
        raise sppasIOError(proto)
    try:
        self._detector = cv2.dnn.readNetFromTensorflow(model, proto)
    except cv2.error as e:
        logging.error('Artificial Neural Network model or proto (TensorFlow) 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), False, False)
    self._detector.setInput(blob)
    return self._detector.forward()