-
Notifications
You must be signed in to change notification settings - Fork 68
Added a Setting to set the Model Download Folder #1557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2020, Joas Schilling <coding@schilljs.com> | ||
| * @copyright Copyright (c) 2021, Marcel Klehr <mklehr@gmx.net> | ||
| * | ||
| * @author Joas Schilling <coding@schilljs.com> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| namespace OCA\Recognize\Migration; | ||
|
|
||
| use OCA\Recognize\Service\SettingsService; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\IRepairStep; | ||
| use Psr\Log\LoggerInterface; | ||
| use function Safe\rename; | ||
| use function Safe\scandir; | ||
|
|
||
| final class MoveDefaultModelFolder implements IRepairStep { | ||
|
|
||
| public function __construct( | ||
| private SettingsService $settingsService, | ||
| private LoggerInterface $logger, | ||
| ) { | ||
| } | ||
|
|
||
| public function getName(): string { | ||
| return 'Try to move the default Model Folder'; | ||
| } | ||
|
|
||
| public function run(IOutput $output): void { | ||
| $oldModelTargetPath = __DIR__ . '/../../models'; | ||
| $oldModelArchivePath = __DIR__ . '/../../models.tar.gz'; | ||
| $newPath = $this->settingsService->getSetting('models_target_path'); | ||
| $newModelTargetPath = $newPath . '/models'; | ||
| $newModelArchivePath = $newPath . '/models.tar.gz'; | ||
|
|
||
| if (is_dir($oldModelTargetPath)) { | ||
| $filesToMove = scandir($oldModelTargetPath); | ||
| $filesToMove = array_filter($filesToMove, fn ($value) => $value !== '.' && $value === '..'); | ||
|
Check failure on line 56 in lib/Migration/MoveDefaultModelFolder.php
|
||
|
a4blue marked this conversation as resolved.
|
||
| $filesToMove = array_map(fn ($value) => $oldModelTargetPath.'/'.$value, $filesToMove); | ||
| mkdir($newModelTargetPath); | ||
|
|
||
| foreach ($filesToMove as $file) { | ||
| rename($file, $newModelTargetPath.'/'.basename($file)); | ||
|
Comment on lines
+59
to
+60
|
||
| } | ||
| } | ||
|
|
||
| if (is_file($oldModelArchivePath)) { | ||
| rename($oldModelArchivePath, $newModelArchivePath); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,23 @@ | |
| </p> | ||
| </template> | ||
| </NcSettingsSection> | ||
| <NcSettingsSection :name="t('recognize', 'Model Setting')"> | ||
| <NcNoteCard v-if="modelsTargetPathWritable" show-alert type="success"> | ||
| {{ t('recognize', 'The Model Target Path is Writable') }} | ||
| </NcNoteCard> | ||
| <NcNoteCard v-else-if="!modelsTargetPathWritable" show-alert type="warning"> | ||
| {{ t('recognize', 'Model Target Path is not Writable') }} | ||
| </NcNoteCard> | ||
| <p> | ||
| <NcTextField v-model="settings['models_target_path']" | ||
| :label="t('recognize', 'Path Model Folder')" | ||
| :label-visible="true" | ||
| @update:model-value="onChange" /> | ||
| </p> | ||
| <p> | ||
| {{ t('recognize', 'Changing this Value will require you to redownload the Models. Also the models in the old Directory need to be deleted manually') }} | ||
| </p> | ||
| </NcSettingsSection> | ||
| <NcSettingsSection :name="t('recognize', 'Classifier backend')"> | ||
| <NcNoteCard v-if="recognizeBackendInstalled" type="success"> | ||
| {{ t('recognize', 'The recognize_backend ExApp is installed; TaskProcessing mode is recommended.') }} | ||
|
|
@@ -81,8 +98,8 @@ | |
| {{ t('recognize', 'Enable face recognition (groups photos by faces that appear in them; UI is in the photos app)') }} | ||
| </NcCheckboxRadioSwitch> | ||
| <NcTextField v-if="!settings['taskprocessing.enabled']" | ||
| :disabled="!settings['faces.enabled']" | ||
| v-model="settings['faces.batchSize']" | ||
| :disabled="!settings['faces.enabled']" | ||
| :label-visible="true" | ||
| :label="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~500 or more, in WASM mode ~50 is recommended)')" | ||
| :title="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~500 or more, in WASM mode ~50 is recommended)')" | ||
|
|
@@ -130,8 +147,8 @@ | |
| {{ t('recognize', 'Enable object recognition (e.g. food, vehicles, landscapes)') }} | ||
| </NcCheckboxRadioSwitch> | ||
| <NcTextField v-if="!settings['taskprocessing.enabled']" | ||
| :disabled="!settings['imagenet.enabled']" | ||
| v-model="settings['imagenet.batchSize']" | ||
| :disabled="!settings['imagenet.enabled']" | ||
| :label-visible="true" | ||
| :label="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~100 or more, in WASM mode ~20 is recommended)')" | ||
| :title="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~100 or more, in WASM mode ~20 is recommended)')" | ||
|
|
@@ -146,8 +163,8 @@ | |
| {{ t('recognize', 'Enable landmark recognition (e.g. Eiffel Tower, Golden Gate Bridge)') }} | ||
| </NcCheckboxRadioSwitch> | ||
| <NcTextField v-if="!settings['taskprocessing.enabled']" | ||
| :disabled="!settings['imagenet.enabled'] || !settings['landmarks.enabled']" | ||
| v-model="settings['landmarks.batchSize']" | ||
| :disabled="!settings['imagenet.enabled'] || !settings['landmarks.enabled']" | ||
| :label-visible="true" | ||
| :label="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~100 or more, in WASM mode ~20 is recommended)')" | ||
| :title="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~100 or more, in WASM mode ~20 is recommended)')" | ||
|
|
@@ -177,8 +194,8 @@ | |
| {{ t('recognize', 'Enable music genre recognition (e.g. pop, rock, folk, metal, new age)') }} | ||
| </NcCheckboxRadioSwitch> | ||
| <NcTextField v-if="!settings['taskprocessing.enabled']" | ||
| :disabled="!settings['musicnn.enabled']" | ||
| v-model="settings['musicnn.batchSize']" | ||
| :disabled="!settings['musicnn.enabled']" | ||
| :label-visible="true" | ||
| :label="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~100 or more, in WASM mode ~20 is recommended)')" | ||
| :title="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~100 or more, in WASM mode ~20 is recommended)')" | ||
|
|
@@ -211,8 +228,8 @@ | |
| {{ t('recognize', 'Enable human action recognition (e.g. arm wrestling, dribbling basketball, hula hooping)') }} | ||
| </NcCheckboxRadioSwitch> | ||
| <NcTextField v-if="!settings['taskprocessing.enabled']" | ||
| :disabled="!settings['movinet.enabled']" | ||
| v-model="settings['movinet.batchSize']" | ||
| :disabled="!settings['movinet.enabled']" | ||
| :label-visible="true" | ||
| :label="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~20 or more, in WASM mode ~5 is recommended)')" | ||
| :title="t('recognize', 'The number of files to process per job run (A job will be scheduled every 5 minutes; For normal operation ~20 or more, in WASM mode ~5 is recommended)')" | ||
|
|
@@ -445,7 +462,7 @@ const TASK_PROCESSING_TASK_TYPES = { | |
| musicnn: 'recognize:audio:classification', | ||
| } | ||
|
|
||
| const SETTINGS = ['tensorflow.cores', 'tensorflow.gpu', 'tensorflow.purejs', 'imagenet.enabled', 'landmarks.enabled', 'faces.enabled', 'musicnn.enabled', 'movinet.enabled', 'node_binary', 'ffmpeg_binary', 'faces.status', 'imagenet.status', 'landmarks.status', 'movinet.status', 'musicnn.status', 'faces.lastFile', 'imagenet.lastFile', 'landmarks.lastFile', 'movinet.lastFile', 'musicnn.lastFile', 'faces.batchSize', 'imagenet.batchSize', 'landmarks.batchSize', 'movinet.batchSize', 'musicnn.batchSize', 'clusterFaces.status', 'clusterFaces.lastRun', 'nice_binary', 'nice_value', 'concurrency.enabled', 'taskprocessing.enabled'] | ||
| const SETTINGS = ['tensorflow.cores', 'tensorflow.gpu', 'tensorflow.purejs', 'imagenet.enabled', 'landmarks.enabled', 'faces.enabled', 'musicnn.enabled', 'movinet.enabled', 'node_binary', 'ffmpeg_binary', 'faces.status', 'imagenet.status', 'landmarks.status', 'movinet.status', 'musicnn.status', 'faces.lastFile', 'imagenet.lastFile', 'landmarks.lastFile', 'movinet.lastFile', 'musicnn.lastFile', 'faces.batchSize', 'imagenet.batchSize', 'landmarks.batchSize', 'movinet.batchSize', 'musicnn.batchSize', 'clusterFaces.status', 'clusterFaces.lastRun', 'nice_binary', 'nice_value', 'concurrency.enabled', 'taskprocessing.enabled', 'models_target_path', 'models_archive_file'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing is probably not what we want though. We should add it to SettingsService |
||
|
|
||
| const BOOLEAN_SETTINGS = ['tensorflow.gpu', 'tensorflow.purejs', 'imagenet.enabled', 'landmarks.enabled', 'faces.enabled', 'musicnn.enabled', 'movinet.enabled', 'faces.status', 'imagenet.status', 'landmarks.status', 'movinet.status', 'musicnn.status', 'faces.lastFile', 'imagenet.lastFile', 'landmarks.lastFile', 'movinet.lastFile', 'musicnn.lastFile', 'clusterFaces.status', 'concurrency.enabled', 'taskprocessing.enabled'] | ||
|
|
||
|
|
@@ -487,6 +504,7 @@ export default { | |
| musicnnTpStats: null, | ||
| tagsEnabled: null, | ||
| recognizeBackendInstalled: false, | ||
| modelsTargetPathWritable: null, | ||
| } | ||
| }, | ||
|
|
||
|
|
@@ -523,6 +541,7 @@ export default { | |
| }, | ||
| async created() { | ||
| this.modelsDownloaded = loadState('recognize', 'modelsDownloaded') | ||
| this.modelsTargetPathWritable = loadState('recognize', 'modelsTargetPathWritable') | ||
| this.tagsEnabled = loadState('recognize', 'tagsEnabled') | ||
| this.recognizeBackendInstalled = loadState('recognize', 'recognizeBackendInstalled', false) | ||
| this.getCount() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.