|
4 | 4 |
|
5 | 5 | class AbstractInferenceEngine(ABC): |
6 | 6 |
|
7 | | - def __init__(self, model_path): |
8 | | - """ |
9 | | - Takes a model path and calls the load function. |
10 | | - :param model_path: The model's path |
11 | | - :return: |
12 | | - """ |
13 | | - self.labels = [] |
14 | | - self.configuration = {} |
15 | | - self.model_path = model_path |
16 | | - try: |
17 | | - self.validate_configuration() |
18 | | - except ApplicationError as e: |
19 | | - raise e |
20 | | - try: |
21 | | - self.load() |
22 | | - except ApplicationError as e: |
23 | | - raise e |
24 | | - except Exception as e: |
25 | | - raise ModelNotLoaded() |
| 7 | + def __init__(self, model_path): |
| 8 | + """ |
| 9 | + Takes a model path and calls the load function. |
| 10 | + :param model_path: The model's path |
| 11 | + :return: |
| 12 | + """ |
| 13 | + self.labels = [] |
| 14 | + self.configuration = {} |
| 15 | + self.model_path = model_path |
| 16 | + try: |
| 17 | + self.validate_configuration() |
| 18 | + except ApplicationError as e: |
| 19 | + raise e |
| 20 | + try: |
| 21 | + self.load() |
| 22 | + except ApplicationError as e: |
| 23 | + raise e |
| 24 | + except Exception as e: |
| 25 | + print(e) |
| 26 | + raise ModelNotLoaded() |
26 | 27 |
|
27 | | - @abstractmethod |
28 | | - def load(self): |
29 | | - """ |
30 | | - Loads the model based on the underlying implementation. |
31 | | - """ |
32 | | - pass |
| 28 | + @abstractmethod |
| 29 | + def load(self): |
| 30 | + """ |
| 31 | + Loads the model based on the underlying implementation. |
| 32 | + """ |
| 33 | + pass |
33 | 34 |
|
34 | | - @abstractmethod |
35 | | - def free(self): |
36 | | - """ |
37 | | - Performs any manual memory implementation required to when unloading a model. |
38 | | - Will be called when the class's destructor is called. |
39 | | - """ |
40 | | - pass |
| 35 | + @abstractmethod |
| 36 | + def free(self): |
| 37 | + """ |
| 38 | + Performs any manual memory implementation required to when unloading a model. |
| 39 | + Will be called when the class's destructor is called. |
| 40 | + """ |
| 41 | + pass |
41 | 42 |
|
42 | | - @abstractmethod |
43 | | - async def run(self, input_data, draw_boxes, predict_batch): |
44 | | - """ |
45 | | - Performs the required inference based on the underlying implementation of this class. |
46 | | - Could be used to return classification predictions, object detection coordinates... |
47 | | - :param predict_batch: Boolean |
48 | | - :param input_data: A single image |
49 | | - :param draw_boxes: Used to draw bounding boxes on image instead of returning them |
50 | | - :return: A bounding-box |
51 | | - """ |
52 | | - pass |
| 43 | + @abstractmethod |
| 44 | + async def infer(self, input_data, draw, predict_batch): |
| 45 | + """ |
| 46 | + Performs the required inference based on the underlying implementation of this class. |
| 47 | + Could be used to return classification predictions, object detection coordinates... |
| 48 | + :param predict_batch: Boolean |
| 49 | + :param input_data: A single image |
| 50 | + :param draw: Used to draw bounding boxes on image instead of returning them |
| 51 | + :return: A bounding-box |
| 52 | + """ |
| 53 | + pass |
53 | 54 |
|
54 | | - @abstractmethod |
55 | | - async def run_batch(self, input_data, draw_boxes, predict_batch): |
56 | | - """ |
57 | | - Iterates over images and returns a prediction for each one. |
58 | | - :param predict_batch: Boolean |
59 | | - :param input_data: List of images |
60 | | - :param draw_boxes: Used to draw bounding boxes on image instead of returning them |
61 | | - :return: List of bounding-boxes |
62 | | - """ |
63 | | - pass |
| 55 | + @abstractmethod |
| 56 | + async def run_batch(self, input_data, draw, predict_batch): |
| 57 | + """ |
| 58 | + Iterates over images and returns a prediction for each one. |
| 59 | + :param predict_batch: Boolean |
| 60 | + :param input_data: List of images |
| 61 | + :param draw: Used to draw bounding boxes on image instead of returning them |
| 62 | + :return: List of bounding-boxes |
| 63 | + """ |
| 64 | + pass |
64 | 65 |
|
65 | | - @abstractmethod |
66 | | - def validate_configuration(self): |
67 | | - """ |
68 | | - Validates that the model and its files are valid based on the underlying implementation's requirements. |
69 | | - Can check for configuration values, folder structure... |
70 | | - """ |
71 | | - pass |
| 66 | + @abstractmethod |
| 67 | + def validate_configuration(self): |
| 68 | + """ |
| 69 | + Validates that the model and its files are valid based on the underlying implementation's requirements. |
| 70 | + Can check for configuration values, folder structure... |
| 71 | + """ |
| 72 | + pass |
72 | 73 |
|
73 | | - @abstractmethod |
74 | | - def set_configuration(self, data): |
75 | | - """ |
76 | | - Takes the configuration from the config.json file |
77 | | - :param data: Json data |
78 | | - :return: |
79 | | - """ |
80 | | - pass |
| 74 | + @abstractmethod |
| 75 | + def set_model_configuration(self, data): |
| 76 | + """ |
| 77 | + Takes the configuration from the config.json file |
| 78 | + :param data: Json data |
| 79 | + :return: |
| 80 | + """ |
| 81 | + pass |
81 | 82 |
|
82 | | - @abstractmethod |
83 | | - def validate_json_configuration(self, data): |
84 | | - """ |
85 | | - Validates the configuration of the config.json file. |
86 | | - :param data: Json data |
87 | | - :return: |
88 | | - """ |
89 | | - pass |
| 83 | + @abstractmethod |
| 84 | + def validate_json_configuration(self, data): |
| 85 | + """ |
| 86 | + Validates the configuration of the config.json file. |
| 87 | + :param data: Json data |
| 88 | + :return: |
| 89 | + """ |
| 90 | + pass |
90 | 91 |
|
91 | | - def __del__(self): |
92 | | - self.free() |
| 92 | + def __del__(self): |
| 93 | + self.free() |
0 commit comments