пользователь сделает селфи, и я сравню эту фотографию с задней фотографией
поэтому у меня есть два изображения
я хочу проверить, один и тот же человек или нет
я используя 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);
}
пользователь сделает селфи, и я сравню эту фотографию с задней фотографией поэтому у меня есть два изображения я хочу проверить, один и тот же человек или нет я используя [b]tflite_flutter 0.9.1[/b] и установленный install.bat это функция, которую я получаю от [b]chatGPT-4[/b] [code]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); } [/code] [b]#это вывод терминала[/b] [code][log] outputShape [1, 192]