mattn / go-tflite

Go binding for TensorFlow Lite
MIT License
304 stars 44 forks source link

Face detection #43

Closed zmajew closed 2 years ago

zmajew commented 2 years ago

Hi, can come of the examples be used for face detection (not recognition) to crop the face from the image, like in TensorFlow mtcnn?

mattn commented 2 years ago

This?

https://github.com/mattn/go-tflite/tree/master/_example/blazeface

zmajew commented 2 years ago

Thank you for your prompt reply! Can it work without gocv, but with the image from the file? So, if I replace "ff, err := resized.DataPtrFloat32()" from line 71 with image converted into []float32 slice, will it return face coordinates? Please, excuse me if I missed something major since I am entering tflite field

mattn commented 2 years ago

You can refer label_image.

https://github.com/mattn/go-tflite/blob/78bc1655490a8ff4464ae50cdd5b40a268133199/_example/label_image/main.go#L94

zmajew commented 2 years ago

I want to detect and then crop the human face from the image. label_image example recognizes the images?

mattn commented 2 years ago

Do you have experience doing that in Python?

zmajew commented 2 years ago

We want to switch from python to the golang. I did face detection with dlib and TensorFlow, but I want to do that with tflite if it is possible.

mattn commented 2 years ago

If you have experience using tflite in Python and a little knowledge of Go, you should be able to do that.

zmajew commented 2 years ago

I have inherited the project from python, and it uses ultraface python for face detection. Your blazeface example looks promising but I do not know now if the face detection is done with tflite or with gocv there? And if it is, what format of image I should send to the model

mattn commented 2 years ago

blazeface example is using tflite to recognize faces. gocv (OpenCV) is used only for getting real-time video.

zmajew commented 2 years ago

I got the cropped image. First, convert image.Image to [][][3]float32, than plain rearrange it to the []float32 and copy it input.Float32s(). Thank you for the help!