Сравнить два изображения с распознаванием лиц с помощью tflite_flutter, но возникла проблема в кодеAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Сравнить два изображения с распознаванием лиц с помощью tflite_flutter, но возникла проблема в коде

Сообщение Anonymous »

пользователь сделает селфи, и я сравню эту фотографию с задней фотографией
поэтому у меня есть два изображения
я хочу проверить, один и тот же человек или нет
я используя tflite_flutter 0.9.1 и установленный install.bat
это функция, которую я получаю от chatGPT-4

Код: Выделить всё

Future compareImages(String imagePath1, String imagePath2) async {
final inputImage1 = InputImage.fromFilePath(imagePath1);
final inputImage2 = InputImage.fromFilePath(imagePath2);

final faceDetector = GoogleMlKit.vision.faceDetector();
final faces1 = await faceDetector.processImage(inputImage1);
final faces2 = await faceDetector.processImage(inputImage2);

if (faces1.isEmpty || faces2.isEmpty) {
return false;
}

// Load the TFLite model
const modelPath = 'mobilefacenet.tflite';
// final modelFile = File(modelPath);
final model =
await Interpreter.fromAsset(modelPath, options: InterpreterOptions());

// Define input and output shapes
final inputShape = model.getInputTensor(0).shape;
final outputShape = model.getOutputTensor(0).shape;

// Prepare input tensors
final input1 = _prepareInputTensor(inputImage1, inputShape);
final input2 = _prepareInputTensor(inputImage2, inputShape);

// Run inference
final output1 = List.filled(outputShape[1], 0.0).reshape([1, outputShape[1]]);
final output2 = List.filled(outputShape[1], 0.0).reshape([1, outputShape[1]]);
dev.log("outputShape $outputShape");
dev.log("output1 $output1");
dev.log("output2 $output2");
model.run(input1, output1);
model.run(input2, output2);

// Compute the distance between the embeddings
final distance = _euclideanDistance(output1[0], output2[0]);

return distance < 0.6;
}

Float32List _prepareInputTensor(InputImage inputImage, List inputShape) {
// Pre-process the input image according to the model's requirements
// For example: resize, normalize, etc.
final inputData = Float32List(
inputShape[0] * inputShape[1] * inputShape[2] * inputShape[3]);
// Fill `inputData` with pre-processed image data
return inputData;
}

double _euclideanDistance(List a, List b) {
double sum = 0.0;
for (int i = 0; i < a.length;  i++) {
double diff = a[i] - b[i];
sum += diff * diff;
}
return sqrt(sum);
}
#это вывод терминала

Код: Выделить всё

[log] outputShape [1, 192]

E/tflite  (28254): tensorflow/lite/kernels/conv.cc:346 input->dims->size != 4 (1 != 4)

E/tflite  (28254): Node number 0 (CONV_2D) failed to prepare.

E/flutter (28254): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad
state: failed precondition

E/flutter (28254): #0      checkState

check.dart:74
E/flutter (28254): #1      Interpreter.allocateTensors

interpreter.dart:142
E/flutter (28254): #2      Interpreter.runForMultipleInputs

interpreter.dart:180
E/flutter (28254): #3      Interpreter.run
interpreter.dart:157
E/flutter (28254): #4      compareImages

face_detection_helper.dart:40

E/flutter (28254): 

E/flutter (28254): #5      _ISignSignOutScreenState.getCurrentView.

ISignSignOutScreen.dart:493

E/flutter (28254): 

E/flutter (28254): #6      _CustomButtonState.build.

CustomButton.dart:84

E/flutter (28254): 

E/flutter (28254):

[log] output1 [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
также мне интересно, почему все выходные данные равны нулям
как это исправить

Подробнее здесь: https://stackoverflow.com/questions/759 ... but-have-i
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»