Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

""" 

@file 

@brief Base class for deep learning models. 

""" 

import os 

 

 

class DeepLearningBase: 

""" 

Implements a common interface to manipulate pre-trained 

deep learning models. 

""" 

 

def __init__(self, model, gpu, fLOG=None): 

""" 

@param model model (url, filename, ...) 

@param gpu use gpu 

@param fLOG logging function 

""" 

self._gpu = gpu 

if model is None: 

raise ValueError("model must be specified") 

if isinstance(model, str): 

if not os.path.exists(model): 

raise FileNotFoundError("Unable to find '{0}'".format(model)) 

raise NotImplementedError( 

"Unable to load model '{0}'".format(model)) 

else: 

self._model = model 

self._fLOG = fLOG 

 

def log(self, *l, **p): 

""" 

Log something. 

""" 

if self._fLOG: 

self._fLOG(*l, **p) 

 

def predict(self, X): 

""" 

Applies the model on features *X*. 

 

@param X features 

@return prediction 

""" 

raise NotImplementedError("Method predict is not implemented.") 

 

 

class DeepLearningImage(DeepLearningBase): 

""" 

Implements a common interface to manipulate pre-trained 

deep learning models processing images. 

""" 

 

def __init__(self, model, gpu=False, fLOG=None): 

""" 

@param model model name 

@param gpu use gpu 

@param fLOG logging function 

""" 

DeepLearningBase.__init__(self, model, gpu=gpu, fLOG=fLOG)