Handle int value in embedding
This commit is contained in:
@@ -59,7 +59,7 @@ class Face {
|
||||
return Face(
|
||||
faceID,
|
||||
fileID,
|
||||
List<double>.from(json['embedding'] as List),
|
||||
parseAsDoubleList(json['embedding'] as List),
|
||||
json['score'] as double,
|
||||
Detection.fromJson(json['detection'] as Map<String, dynamic>),
|
||||
// high value means t
|
||||
@@ -77,3 +77,21 @@ class Face {
|
||||
'blur': blur,
|
||||
};
|
||||
}
|
||||
|
||||
List<double> parseAsDoubleList(List<dynamic> inputList) {
|
||||
if (inputList.isEmpty) return const [];
|
||||
|
||||
if (inputList is List<double>) return inputList;
|
||||
return List<double>.generate(
|
||||
inputList.length,
|
||||
(index) {
|
||||
final value = inputList[index];
|
||||
if (value is int) return value.toDouble();
|
||||
if (value is double) return value;
|
||||
throw FormatException(
|
||||
'Invalid type at index $index: ${value.runtimeType}',
|
||||
);
|
||||
},
|
||||
growable: false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ class RemoteClipEmbedding {
|
||||
// fromJson
|
||||
factory RemoteClipEmbedding.fromJson(Map<String, dynamic> json) {
|
||||
return RemoteClipEmbedding(
|
||||
List<double>.from(json['embedding'] as List),
|
||||
parseAsDoubleList(json['embedding'] as List),
|
||||
version: json['version'] as int,
|
||||
client: json['client'] as String,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user