1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017-2020 Matias De lellis <[email protected]> |
4
|
|
|
* @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @author Branko Kokanovic <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\FaceRecognition\BackgroundJob\Tasks; |
26
|
|
|
|
27
|
|
|
use OCP\Util as OCP_Util; |
28
|
|
|
|
29
|
|
|
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionBackgroundTask; |
30
|
|
|
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionContext; |
31
|
|
|
|
32
|
|
|
use OCA\FaceRecognition\Helper\Imaginary; |
33
|
|
|
use OCA\FaceRecognition\Helper\MemoryLimits; |
34
|
|
|
use OCA\FaceRecognition\Helper\Requirements; |
35
|
|
|
|
36
|
|
|
use OCA\FaceRecognition\Model\IModel; |
37
|
|
|
use OCA\FaceRecognition\Model\ModelManager; |
38
|
|
|
|
39
|
|
|
use OCA\FaceRecognition\Service\SettingsService; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check all requirements before we start engaging in lengthy background task. |
43
|
|
|
*/ |
44
|
|
|
class CheckRequirementsTask extends FaceRecognitionBackgroundTask { |
45
|
|
|
|
46
|
|
|
/** @var ModelManager Model Manader */ |
47
|
|
|
private $modelManager; |
48
|
|
|
|
49
|
|
|
/** @var SettingsService Settings service */ |
50
|
|
|
private $settingsService; |
51
|
|
|
|
52
|
|
|
/** @var Imaginary imaginary helper */ |
53
|
|
|
private $imaginaryHelper; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param ModelManager $modelManager Model Manager |
57
|
|
|
* @param SettingsService $settingsService Settings service |
58
|
|
|
* @param Imaginary $imaginaryHelper imaginary helper |
59
|
|
|
*/ |
60
|
|
|
public function __construct(ModelManager $modelManager, |
61
|
|
|
SettingsService $settingsService, |
62
|
|
|
Imaginary $imaginaryHelper) |
63
|
|
|
{ |
64
|
|
|
parent::__construct(); |
65
|
|
|
|
66
|
|
|
$this->modelManager = $modelManager; |
67
|
|
|
$this->settingsService = $settingsService; |
68
|
|
|
$this->imaginaryHelper = $imaginaryHelper; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritdoc |
73
|
|
|
*/ |
74
|
|
|
public function description() { |
75
|
|
|
return "Check all requirements"; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritdoc |
80
|
|
|
*/ |
81
|
|
|
public function execute(FaceRecognitionContext $context) { |
82
|
|
|
$this->setContext($context); |
83
|
|
|
|
84
|
|
|
$system = php_uname("s"); |
85
|
|
|
$this->logDebug("System: " . $system); |
86
|
|
|
|
87
|
|
|
$systemMemory = MemoryLimits::getSystemMemory(); |
88
|
|
|
$this->logDebug("System memory: " . ($systemMemory > 0 ? $systemMemory : "Unknown")); |
89
|
|
|
|
90
|
|
|
$phpMemory = MemoryLimits::getPhpMemory(); |
91
|
|
|
$this->logDebug("PHP Memory Limit: " . ($phpMemory > 0 ? $phpMemory : "Unknown")); |
92
|
|
|
|
93
|
|
|
if ($this->imaginaryHelper->isEnabled()) { |
94
|
|
|
$this->logDebug("Backend of images: Imaginary"); |
95
|
|
|
$version = $this->imaginaryHelper->getVersion(); |
96
|
|
|
if ($version) { |
97
|
|
|
$this->logDebug("Imaginary version: " . $version); |
98
|
|
|
} else { |
99
|
|
|
$imaginaryUrl = $this->imaginaryHelper->getUrl(); |
100
|
|
|
$error_message = |
101
|
|
|
"An Imaginary service (" . $imaginaryUrl . ") was configured to manage temporary images, but it is inaccessible." . |
102
|
|
|
"Check out the service, or set the 'preview_imaginary_url' key appropriately."; |
103
|
|
|
$this->logInfo($error_message); |
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
} else { |
107
|
|
|
$this->logDebug("Backend of images: Imagick"); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (!Requirements::pdlibLoaded()) { |
111
|
|
|
$error_message = |
112
|
|
|
"The PDlib PHP extension is not loaded. Cannot continue without it." . |
113
|
|
|
"Please read the documentation again about how to install the application: https://github.com/matiasdelellis/facerecognition/wiki/Installation"; |
114
|
|
|
$this->logInfo($error_message); |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (!Requirements::hasEnoughMemory()) { |
119
|
|
|
$error_message = |
120
|
|
|
"Your system does not meet the minimum of memory requirements.\n" . |
121
|
|
|
"Face recognition application requires at least " . OCP_Util::humanFileSize(SettingsService::MINIMUM_SYSTEM_MEMORY_REQUIREMENTS) . " of system memory.\n" . |
122
|
|
|
"See https://github.com/matiasdelellis/facerecognition/wiki/Performance-analysis-of-DLib%E2%80%99s-CNN-face-detection for more details\n\n" . |
123
|
|
|
"Fill an issue here if that doesn't help: https://github.com/matiasdelellis/facerecognition/issues"; |
124
|
|
|
$this->logInfo($error_message); |
125
|
|
|
return false; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$model = $this->modelManager->getCurrentModel(); |
129
|
|
|
if (is_null($model)) { |
130
|
|
|
$error_message = |
131
|
|
|
"Seems there are no installed models.\n" . |
132
|
|
|
"Please read the documentation about this: https://github.com/matiasdelellis/facerecognition/wiki/Models#install-models\n" . |
133
|
|
|
"and install them with the 'occ face:setup --model MODEL_ID' command.\n\n" . |
134
|
|
|
"Fill an issue here if that doesn't help: https://github.com/matiasdelellis/facerecognition/issues"; |
135
|
|
|
$this->logInfo($error_message); |
136
|
|
|
return false; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$model_message = ''; |
140
|
|
|
if (!$model->meetDependencies($model_message)) { |
141
|
|
|
$error_message = |
142
|
|
|
"Seems that don't meet the dependencies to use the model " . $model->getId() . ": " . $model->getName() . "\n". |
143
|
|
|
"Resume: " . $model_message . "\n" . |
144
|
|
|
"Please read the documentation for this model to continue: " . $model->getDocumentation() . "\n\n" . |
145
|
|
|
"Fill an issue here if that doesn't help: https://github.com/matiasdelellis/facerecognition/issues"; |
146
|
|
|
$this->logInfo($error_message); |
147
|
|
|
return false; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$imageArea = $this->settingsService->getAnalysisImageArea(); |
151
|
|
|
if ($imageArea < 0) { |
152
|
|
|
$error_message = |
153
|
|
|
"Seems that still don't configured the image area used for temporary files.\n" . |
154
|
|
|
"Please read the documentation about this: https://github.com/matiasdelellis/facerecognition/wiki/Settings#temporary-files\n" . |
155
|
|
|
"and then configure it in the admin panel to continue\n\n" . |
156
|
|
|
"Fill an issue here if that doesn't help: https://github.com/matiasdelellis/facerecognition/issues"; |
157
|
|
|
$this->logInfo($error_message); |
158
|
|
|
return false; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$maxImageArea = $model->getMaximumArea(); |
162
|
|
|
if ($imageArea > $maxImageArea) { |
163
|
|
|
$error_message = |
164
|
|
|
"There are inconsistencies between the configured image area (" . $imageArea. " pixels^2) which is\n" . |
165
|
|
|
"greater that the maximum allowed by the model (". $maxImageArea . " pixels^2).\n" . |
166
|
|
|
"Please check and fix it in the admin panel to continue.\n\n" . |
167
|
|
|
"Fill an issue here if that doesn't help: https://github.com/matiasdelellis/facerecognition/issues"; |
168
|
|
|
$this->logInfo($error_message); |
169
|
|
|
return false; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return true; |
173
|
|
|
} |
174
|
|
|
} |