1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2020, Matias De lellis <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Matias De lellis <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\FaceRecognition\Model; |
25
|
|
|
|
26
|
|
|
use OCP\IConfig; |
27
|
|
|
use OCP\Files\IAppData; |
28
|
|
|
use OCP\Files\IRootFolder; |
29
|
|
|
use OCP\Files\NotFoundException; |
30
|
|
|
|
31
|
|
|
use OCA\FaceRecognition\Model\IModel; |
32
|
|
|
|
33
|
|
|
use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnn68Model; |
34
|
|
|
use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnn5Model; |
35
|
|
|
|
36
|
|
|
use OCA\FaceRecognition\Model\DlibHogModel\DlibHogModel; |
37
|
|
|
|
38
|
|
|
class ModelManager { |
39
|
|
|
|
40
|
|
|
/** Defines ID for default face model */ |
41
|
|
|
const DEFAULT_FACE_MODEL_ID = 1; |
42
|
|
|
|
43
|
|
|
/** @var DlibCnn5Model */ |
44
|
|
|
private $dlibCnn5Model; |
45
|
|
|
|
46
|
|
|
/** @var DlibCnn68Model */ |
47
|
|
|
private $dlibCnn68Model; |
48
|
|
|
|
49
|
|
|
/** @var DlibHogModel */ |
50
|
|
|
private $dlibHogModel; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param DlibCnn5Model $dlibCnn5Model |
54
|
|
|
* @param DlibCnn68Model $dlibCnn68Model |
55
|
|
|
* @param DlibHogModel $dlibHogModel |
56
|
|
|
*/ |
57
|
|
|
public function __construct(DlibCnn5Model $dlibCnn5Model, |
58
|
|
|
DlibCnn68Model $dlibCnn68Model, |
59
|
|
|
DlibHogModel $dlibHogModel) |
60
|
|
|
{ |
61
|
|
|
$this->dlibCnn5Model = $dlibCnn5Model; |
62
|
|
|
$this->dlibCnn68Model = $dlibCnn68Model; |
63
|
|
|
$this->dlibHogModel = $dlibHogModel; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $version model version |
68
|
|
|
* @return IModel|null |
69
|
|
|
*/ |
70
|
|
|
public function getModel(int $version): ?IModel { |
71
|
|
|
switch ($version) { |
72
|
|
|
case 1: |
73
|
|
|
$model = $this->dlibCnn5Model; |
74
|
|
|
break; |
75
|
|
|
case 2: |
76
|
|
|
$model = $this->dlibCnn68Model; |
77
|
|
|
break; |
78
|
|
|
case 3: |
79
|
|
|
$model = $this->dlibHogModel; |
80
|
|
|
break; |
81
|
|
|
default: |
82
|
|
|
$model = null; |
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
return $model; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |