1
"""
2
@file
3
@brief Base class for deep learning models.
4
"""
5 1
import os
6

7

8 1
class DeepLearningBase:
9
    """
10
    Implements a common interface to manipulate pre-trained
11
    deep learning models.
12
    """
13

14 1
    def __init__(self, model, gpu, fLOG=None):
15
        """
16
        @param      model       model (url, filename, ...)
17
        @param      gpu         use gpu
18
        @param      fLOG        logging function
19
        """
20 1
        self._gpu = gpu
21 1
        if model is None:
22 0
            raise ValueError("model must be specified")
23 1
        if isinstance(model, str):
24 0
            if not os.path.exists(model):
25 0
                raise FileNotFoundError("Unable to find '{0}'".format(model))
26 0
            raise NotImplementedError(
27
                "Unable to load model '{0}'".format(model))
28 1
        self._model = model
29 1
        self._fLOG = fLOG
30

31 1
    def log(self, *args, **kwargs):
32
        """
33
        Log something.
34
        """
35 1
        if self._fLOG:
36 1
            self._fLOG(*args, **kwargs)
37

38 1
    def predict(self, X):
39
        """
40
        Applies the model on features *X*.
41

42
        @param      X       features
43
        @return             prediction
44
        """
45 0
        raise NotImplementedError("Method predict is not implemented.")
46

47

48 1
class DeepLearningImage(DeepLearningBase):
49
    """
50
    Implements a common interface to manipulate pre-trained
51
    deep learning models processing images.
52
    """
53

54 1
    def __init__(self, model, gpu=False, fLOG=None):
55
        """
56
        @param      model       model name
57
        @param      gpu         use gpu
58
        @param      fLOG        logging function
59
        """
60 1
        DeepLearningBase.__init__(self, model, gpu=gpu, fLOG=fLOG)

Read our documentation on viewing source code .

Loading