1
0
mirror of https://github.com/immich-app/immich.git synced 2025-07-17 10:07:48 +02:00

feat(ml)!: customizable ML settings (#3891)

* consolidated endpoints, added live configuration

* added ml settings to server

* added settings dashboard

* updated deps, fixed typos

* simplified modelconfig

updated tests

* Added ml setting accordion for admin page

updated tests

* merge `clipText` and `clipVision`

* added face distance setting

clarified setting

* add clip mode in request, dropdown for face models

* polished ml settings

updated descriptions

* update clip field on error

* removed unused import

* add description for image classification threshold

* pin safetensors for arm wheel

updated poetry lock

* moved dto

* set model type only in ml repository

* revert form-data package install

use fetch instead of axios

* added slotted description with link

updated facial recognition description

clarified effect of disabling tasks

* validation before model load

* removed unnecessary getconfig call

* added migration

* updated api

updated api

updated api

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Mert
2023-08-29 09:58:00 -04:00
committed by GitHub
parent 22f5e05060
commit bcc36d14a1
56 changed files with 2324 additions and 655 deletions

View File

@ -0,0 +1,131 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class ClassificationConfig {
/// Returns a new [ClassificationConfig] instance.
ClassificationConfig({
required this.enabled,
required this.minScore,
required this.modelName,
this.modelType,
});
bool enabled;
int minScore;
String modelName;
///
/// Please note: This property should have been non-nullable! Since the specification file
/// does not include a default value (using the "default:" property), however, the generated
/// source code must fall back to having a nullable type.
/// Consider adding a "default:" property in the specification file to hide this note.
///
ModelType? modelType;
@override
bool operator ==(Object other) => identical(this, other) || other is ClassificationConfig &&
other.enabled == enabled &&
other.minScore == minScore &&
other.modelName == modelName &&
other.modelType == modelType;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(enabled.hashCode) +
(minScore.hashCode) +
(modelName.hashCode) +
(modelType == null ? 0 : modelType!.hashCode);
@override
String toString() => 'ClassificationConfig[enabled=$enabled, minScore=$minScore, modelName=$modelName, modelType=$modelType]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'enabled'] = this.enabled;
json[r'minScore'] = this.minScore;
json[r'modelName'] = this.modelName;
if (this.modelType != null) {
json[r'modelType'] = this.modelType;
} else {
// json[r'modelType'] = null;
}
return json;
}
/// Returns a new [ClassificationConfig] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static ClassificationConfig? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return ClassificationConfig(
enabled: mapValueOfType<bool>(json, r'enabled')!,
minScore: mapValueOfType<int>(json, r'minScore')!,
modelName: mapValueOfType<String>(json, r'modelName')!,
modelType: ModelType.fromJson(json[r'modelType']),
);
}
return null;
}
static List<ClassificationConfig> listFromJson(dynamic json, {bool growable = false,}) {
final result = <ClassificationConfig>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = ClassificationConfig.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, ClassificationConfig> mapFromJson(dynamic json) {
final map = <String, ClassificationConfig>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = ClassificationConfig.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of ClassificationConfig-objects as value to a dart map
static Map<String, List<ClassificationConfig>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<ClassificationConfig>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = ClassificationConfig.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'enabled',
'minScore',
'modelName',
};
}

140
mobile/openapi/lib/model/clip_config.dart generated Normal file
View File

@ -0,0 +1,140 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class CLIPConfig {
/// Returns a new [CLIPConfig] instance.
CLIPConfig({
required this.enabled,
this.mode,
required this.modelName,
this.modelType,
});
bool enabled;
///
/// Please note: This property should have been non-nullable! Since the specification file
/// does not include a default value (using the "default:" property), however, the generated
/// source code must fall back to having a nullable type.
/// Consider adding a "default:" property in the specification file to hide this note.
///
CLIPMode? mode;
String modelName;
///
/// Please note: This property should have been non-nullable! Since the specification file
/// does not include a default value (using the "default:" property), however, the generated
/// source code must fall back to having a nullable type.
/// Consider adding a "default:" property in the specification file to hide this note.
///
ModelType? modelType;
@override
bool operator ==(Object other) => identical(this, other) || other is CLIPConfig &&
other.enabled == enabled &&
other.mode == mode &&
other.modelName == modelName &&
other.modelType == modelType;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(enabled.hashCode) +
(mode == null ? 0 : mode!.hashCode) +
(modelName.hashCode) +
(modelType == null ? 0 : modelType!.hashCode);
@override
String toString() => 'CLIPConfig[enabled=$enabled, mode=$mode, modelName=$modelName, modelType=$modelType]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'enabled'] = this.enabled;
if (this.mode != null) {
json[r'mode'] = this.mode;
} else {
// json[r'mode'] = null;
}
json[r'modelName'] = this.modelName;
if (this.modelType != null) {
json[r'modelType'] = this.modelType;
} else {
// json[r'modelType'] = null;
}
return json;
}
/// Returns a new [CLIPConfig] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static CLIPConfig? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return CLIPConfig(
enabled: mapValueOfType<bool>(json, r'enabled')!,
mode: CLIPMode.fromJson(json[r'mode']),
modelName: mapValueOfType<String>(json, r'modelName')!,
modelType: ModelType.fromJson(json[r'modelType']),
);
}
return null;
}
static List<CLIPConfig> listFromJson(dynamic json, {bool growable = false,}) {
final result = <CLIPConfig>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = CLIPConfig.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, CLIPConfig> mapFromJson(dynamic json) {
final map = <String, CLIPConfig>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = CLIPConfig.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of CLIPConfig-objects as value to a dart map
static Map<String, List<CLIPConfig>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<CLIPConfig>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = CLIPConfig.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'enabled',
'modelName',
};
}

85
mobile/openapi/lib/model/clip_mode.dart generated Normal file
View File

@ -0,0 +1,85 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class CLIPMode {
/// Instantiate a new enum with the provided [value].
const CLIPMode._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const vision = CLIPMode._(r'vision');
static const text = CLIPMode._(r'text');
/// List of all possible values in this [enum][CLIPMode].
static const values = <CLIPMode>[
vision,
text,
];
static CLIPMode? fromJson(dynamic value) => CLIPModeTypeTransformer().decode(value);
static List<CLIPMode>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <CLIPMode>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = CLIPMode.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [CLIPMode] to String,
/// and [decode] dynamic data back to [CLIPMode].
class CLIPModeTypeTransformer {
factory CLIPModeTypeTransformer() => _instance ??= const CLIPModeTypeTransformer._();
const CLIPModeTypeTransformer._();
String encode(CLIPMode data) => data.value;
/// Decodes a [dynamic value][data] to a CLIPMode.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
CLIPMode? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'vision': return CLIPMode.vision;
case r'text': return CLIPMode.text;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [CLIPModeTypeTransformer] instance.
static CLIPModeTypeTransformer? _instance;
}

88
mobile/openapi/lib/model/model_type.dart generated Normal file
View File

@ -0,0 +1,88 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class ModelType {
/// Instantiate a new enum with the provided [value].
const ModelType._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const imageClassification = ModelType._(r'image-classification');
static const facialRecognition = ModelType._(r'facial-recognition');
static const clip = ModelType._(r'clip');
/// List of all possible values in this [enum][ModelType].
static const values = <ModelType>[
imageClassification,
facialRecognition,
clip,
];
static ModelType? fromJson(dynamic value) => ModelTypeTypeTransformer().decode(value);
static List<ModelType>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <ModelType>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = ModelType.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [ModelType] to String,
/// and [decode] dynamic data back to [ModelType].
class ModelTypeTypeTransformer {
factory ModelTypeTypeTransformer() => _instance ??= const ModelTypeTypeTransformer._();
const ModelTypeTypeTransformer._();
String encode(ModelType data) => data.value;
/// Decodes a [dynamic value][data] to a ModelType.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
ModelType? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'image-classification': return ModelType.imageClassification;
case r'facial-recognition': return ModelType.facialRecognition;
case r'clip': return ModelType.clip;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [ModelTypeTypeTransformer] instance.
static ModelTypeTypeTransformer? _instance;
}

View File

@ -0,0 +1,139 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class RecognitionConfig {
/// Returns a new [RecognitionConfig] instance.
RecognitionConfig({
required this.enabled,
required this.maxDistance,
required this.minScore,
required this.modelName,
this.modelType,
});
bool enabled;
int maxDistance;
int minScore;
String modelName;
///
/// Please note: This property should have been non-nullable! Since the specification file
/// does not include a default value (using the "default:" property), however, the generated
/// source code must fall back to having a nullable type.
/// Consider adding a "default:" property in the specification file to hide this note.
///
ModelType? modelType;
@override
bool operator ==(Object other) => identical(this, other) || other is RecognitionConfig &&
other.enabled == enabled &&
other.maxDistance == maxDistance &&
other.minScore == minScore &&
other.modelName == modelName &&
other.modelType == modelType;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(enabled.hashCode) +
(maxDistance.hashCode) +
(minScore.hashCode) +
(modelName.hashCode) +
(modelType == null ? 0 : modelType!.hashCode);
@override
String toString() => 'RecognitionConfig[enabled=$enabled, maxDistance=$maxDistance, minScore=$minScore, modelName=$modelName, modelType=$modelType]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'enabled'] = this.enabled;
json[r'maxDistance'] = this.maxDistance;
json[r'minScore'] = this.minScore;
json[r'modelName'] = this.modelName;
if (this.modelType != null) {
json[r'modelType'] = this.modelType;
} else {
// json[r'modelType'] = null;
}
return json;
}
/// Returns a new [RecognitionConfig] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static RecognitionConfig? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return RecognitionConfig(
enabled: mapValueOfType<bool>(json, r'enabled')!,
maxDistance: mapValueOfType<int>(json, r'maxDistance')!,
minScore: mapValueOfType<int>(json, r'minScore')!,
modelName: mapValueOfType<String>(json, r'modelName')!,
modelType: ModelType.fromJson(json[r'modelType']),
);
}
return null;
}
static List<RecognitionConfig> listFromJson(dynamic json, {bool growable = false,}) {
final result = <RecognitionConfig>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = RecognitionConfig.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, RecognitionConfig> mapFromJson(dynamic json) {
final map = <String, RecognitionConfig>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = RecognitionConfig.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of RecognitionConfig-objects as value to a dart map
static Map<String, List<RecognitionConfig>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<RecognitionConfig>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = RecognitionConfig.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'enabled',
'maxDistance',
'minScore',
'modelName',
};
}

View File

@ -13,49 +13,49 @@ part of openapi.api;
class SystemConfigMachineLearningDto {
/// Returns a new [SystemConfigMachineLearningDto] instance.
SystemConfigMachineLearningDto({
required this.clipEncodeEnabled,
required this.classification,
required this.clip,
required this.enabled,
required this.facialRecognitionEnabled,
required this.tagImageEnabled,
required this.facialRecognition,
required this.url,
});
bool clipEncodeEnabled;
ClassificationConfig classification;
CLIPConfig clip;
bool enabled;
bool facialRecognitionEnabled;
bool tagImageEnabled;
RecognitionConfig facialRecognition;
String url;
@override
bool operator ==(Object other) => identical(this, other) || other is SystemConfigMachineLearningDto &&
other.clipEncodeEnabled == clipEncodeEnabled &&
other.classification == classification &&
other.clip == clip &&
other.enabled == enabled &&
other.facialRecognitionEnabled == facialRecognitionEnabled &&
other.tagImageEnabled == tagImageEnabled &&
other.facialRecognition == facialRecognition &&
other.url == url;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(clipEncodeEnabled.hashCode) +
(classification.hashCode) +
(clip.hashCode) +
(enabled.hashCode) +
(facialRecognitionEnabled.hashCode) +
(tagImageEnabled.hashCode) +
(facialRecognition.hashCode) +
(url.hashCode);
@override
String toString() => 'SystemConfigMachineLearningDto[clipEncodeEnabled=$clipEncodeEnabled, enabled=$enabled, facialRecognitionEnabled=$facialRecognitionEnabled, tagImageEnabled=$tagImageEnabled, url=$url]';
String toString() => 'SystemConfigMachineLearningDto[classification=$classification, clip=$clip, enabled=$enabled, facialRecognition=$facialRecognition, url=$url]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'clipEncodeEnabled'] = this.clipEncodeEnabled;
json[r'classification'] = this.classification;
json[r'clip'] = this.clip;
json[r'enabled'] = this.enabled;
json[r'facialRecognitionEnabled'] = this.facialRecognitionEnabled;
json[r'tagImageEnabled'] = this.tagImageEnabled;
json[r'facialRecognition'] = this.facialRecognition;
json[r'url'] = this.url;
return json;
}
@ -68,10 +68,10 @@ class SystemConfigMachineLearningDto {
final json = value.cast<String, dynamic>();
return SystemConfigMachineLearningDto(
clipEncodeEnabled: mapValueOfType<bool>(json, r'clipEncodeEnabled')!,
classification: ClassificationConfig.fromJson(json[r'classification'])!,
clip: CLIPConfig.fromJson(json[r'clip'])!,
enabled: mapValueOfType<bool>(json, r'enabled')!,
facialRecognitionEnabled: mapValueOfType<bool>(json, r'facialRecognitionEnabled')!,
tagImageEnabled: mapValueOfType<bool>(json, r'tagImageEnabled')!,
facialRecognition: RecognitionConfig.fromJson(json[r'facialRecognition'])!,
url: mapValueOfType<String>(json, r'url')!,
);
}
@ -120,10 +120,10 @@ class SystemConfigMachineLearningDto {
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'clipEncodeEnabled',
'classification',
'clip',
'enabled',
'facialRecognitionEnabled',
'tagImageEnabled',
'facialRecognition',
'url',
};
}