포스트

Face-detection in Flutter

얼굴 인식에 사용하는 AI 모델을 비교한 글이 있어 가져와보았다.

이런 것을 전문적으로 비교하는 논문도 많이 있겠지만, 그렇게 세세하게 볼 필요는 없는 것 같다. 대강 어떤 모델이 유명한지 보면, mobileNet ssd 모델이 유명하다. ㅎㅎ 모델 아키텍처가 가벼워서 추론이 빠르고, 성능도 꿀리지 않는다.

플러터에서 얼굴 인식 기능을 구현하기 위한 여러 시도를 해보았다.

스마트폰에서 사용하기에는 MobileNet이 크기와 성능 면에서 모두 우수하다는 것을 조사했지만, 확인을 위해 직접 시도해보았다.

훈련까지 하는 것은 최후의 방법이고, 이미 훈련한 가중치를 구할 수 있었으므로 그것으로 비교했다.

결과적으로 3가지(mlkit, tensorflow lite, Yolo)를 모두 사용해보았는데, 얼굴 인식은 모두 잘 했다.

그러나 앱을 빌드하고 나니, 각 패키지를 바로 사용하기에는 앱 크기가 많이 차이나는 경우가 있었다.


  1. YoLo v8

다른 분이 훈련한 가중치를 찾았다.

https://github.com/akanametov/yolov8-face/tree/dev

GitHub - akanametov/yolov8-face: YOLOv8 Face 🚀 in PyTorch > ONNX > CoreML > TFLite YOLOv8 Face 🚀 in PyTorch > ONNX > CoreML > TFLite. Contribute to akanametov/yolov8-face development by creating an account on GitHub. YOLOv8 Face 🚀 in PyTorch > ONNX > CoreML > TFLite. Contribute to akanametov/yolov8-face development by creating an account on GitHub.

pytorch 가중치이기 때문에 tensorflow lite 가중치로 변환했다.

이제 Yolo5, Yolo8, 그리고 Tesseract v5 모델에만 특화되어 있는 플러터 플러그인으로 가중치를 사용했다.

https://pub.dev/packages/flutter_vision

flutter_vision | Flutter package Plugin for managing Yolov5, Yolov8 and Tesseract v5 accessing with TensorFlow Lite 2.x. Support object detection, segmentation and OCR on Android. iOS, Working in progress. Plugin for managing Yolov5, Yolov8 and Tesseract v5 accessing with TensorFlow Lite 2.x. Support object detection, segmentation and OCR on Android. iOS, Working in progress.

결과는, 약 220MB

혹시 모델을 하나 더 넣으면 많이 차이나는지, 혹은 정말 패키지 문제인지 확인을 위해, segmentation 기능과 가중치도 같이 넣어서 빌드해보았다.

별 차이가 없다. 역시 패키지가 문제인 것 같다.


  1. mobileNet v1 https://pub.dev/packages/tflite_flutter

tflite_flutter | Flutter package TensorFlow Lite Flutter plugin provides an easy, flexible, and fast Dart API to integrate TFLite models in flutter apps across mobile and desktop platforms. TensorFlow Lite Flutter plugin provides an easy, flexible, and fast Dart API to integrate TFLite models in flutter apps across mobile and desktop platforms.

tflite에는 mobileNet v1, v2가 예제로 구현되어 있다. v2에는 사람에 대한 object detection label이 없어서 아쉽게도 직접 훈련하지 않고는 사용할 수 없을 것 같다. v1에는 사람에 대한 label도 있어서 사람 인식을 테스트해볼 수 있었다. 정말 원하는 기능은 face detection이었지만, 이건 마찬가지로 직접 훈련해야 쓸 수가 있겠다.

앱을 빌드하면,

v1은 약 23MB이고,

v2는 약 50MB이다.

용량의 차이가 있긴 하지만 큰 차이는 아닌 것 같다.


  1. mlkit https://pub.dev/packages/google_ml_kit

google_ml_kit | Flutter package A Flutter plugin to use all APIs from Google's standalone ML Kit for mobile platforms. A Flutter plugin to use all APIs from Google's standalone ML Kit for mobile platforms.

구글 ML kit는 모델을 따로 커스텀 할 수가 없는 듯 하다.

구현은 다른 분이 구현한 코드를 찾아서 사용했다. https://imsnehalsingh.medium.com/google-ml-kit-flutter-part-2-face-detection-365781163b40

Google ML Kit + Flutter: Part 2(Face Detection) Welcome back to the second part of our blog series on integrating Google ML Kit with Flutter! In our previous blog post, we delved into the… Welcome back to the second part of our blog series on integrating Google ML Kit with Flutter! In our previous blog post, we delved into the…

용량은 약 150MB이다.

Yolo를 썼을 때와 마찬가지로 패키지 자체를 수정하는 방법을 시도해야 한다. (된다면)




tensorflow lite 플러터 패키지를 사용하는 편이 좋아보인다. ** **1. 용량을 적게 차지함 2. 커스텀 모델을 가져다가 쓸 수 있음.

sticker




(참조) https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78 ** https://github.com/ageitgey/face_recognition/blob/master/README_Korean.md ** https://we-co.tistory.com/110 ** https://medium.com/modulabs/아-누구시더라-나보다-빠르고-똑똑한-얼굴인식-만들기-ae3e639bd2d3 ** Face detection model 성능 비교(WIDERFace) https://seongkyun.github.io/study/2019/03/25/face_detection/ ** ** Face-detection-with-mobilenet-ssd https://github.com/bruceyang2012/Face-detection-with-mobilenet-ssd ** **데이터셋 https://hongl.tistory.com/185 https://www.aitimes.kr/news/articleView.html?idxno=15924 ** https://github.com/fadhilmch/FaceRecognition **얼굴 감지(mobilenetSSD) 사전 학습된 모델이 제공되는 모바일넷 SSD(Single Shot Multibox Detector) 기반 얼굴 감지기입니다. 참조. **https://github.com/yeephycho/tensorflow-face-Detection ** 얼굴인식(FaceNet) “FaceNet: 얼굴 인식 및 클러스터링을 위한 통합 임베딩” 논문에 설명된 얼굴 인식기의 TensorFlow 구현입니다. 참조. **https://github.com/davidsandberg/facenet ** 얼굴 분류(kNN, SVM) kNN 또는 SVM을 사용하여 FaceNet에서 생성된 특징을 분류합니다. ** ** 모바일폰에서 동작하는 딥러닝 모듈의 성능을 알아보자. (AI-Benchmark) https://inforience.net/2020/10/20/ai-benchmark/ https://greeksharifa.github.io/computer%20vision/2022/02/23/MobileNetV3/ https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/README.md https://velog.io/@pre_f_86/MobileNet-V3-%EB%85%BC%EB%AC%B8-%EB%A6%AC%EB%B7%B0 ** https://github.com/deepinsight/insightface/tree/master/model_zoo https://github.com/deepinsight/insightface ** https://github.com/topics/mobilenetv3?o=desc&s=stars ** https://github.com/akanametov/yolov8-face ** yolov8 vs mobilenet ssd v3 https://keylabs.ai/blog/yolov8-vs-ssd-choosing-the-right-object-detection-model/ ** **YoloV5 vs MobilenetV3 https://github.com/ultralytics/yolov5/issues/1012

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.