face detction/recognization golang lib using tensorflow facenet

Golang lib for detect/recognize by tensorflow facenet

Go Reference Go goreleaser GitHub go.mod Go version of a Go module GoReportCard GitHub license GitHub release

Prerequest

  1. libtensorfow 1.x Follow the instruction Install TensorFlow for C
  2. facenet tenorflow saved_model Google Drive
  3. build the executable
  4. download font(optional) Google Drive
# generated to ./bin/facenet
make facenet

Demo

demo screen capture

Install

go get -u github.com/bububa/facenet

Usage

Train faces

./bin/facenet -model=./models/facenet -db=./models/people.db -train={image folder for training} -output={fold path for output thumbs(optional)}

the train folder include folders which name is the label with images inside

Update distinct labels

./bin/facenet -model=./models/facenet -db=./models/people.db -update={labels for update seperated by comma} -output={fold path for output thumbs(optional)}

Delete distinct labels from people model

./bin/facenet -model=./models/facenet -db=./models/people.db -delete={labels for delete seperated by comma} -output={fold path for output thumbs(optional)}

Detect faces for image

./bin/facenet -model=./models/facenet -db=./models/people.db -detect={the image file path for detecting} -font={font folder for output image(optional)} -output={fold path for output thumbs(optional)}

Camera & Server

Requirements

  • libjpeg-turbo (use -tags jpeg to build without CGo)
  • On Linux/RPi native Go V4L implementation is used to capture images.

Use Opencv4

make cvcamera

On linux/Pi

# use native Go V4L implementation is used to capture images
make linux_camera

Use image/jpeg instead of libjpeg-turbo

use jpeg build tag to build with native Go image/jpeg instead of libjpeg-turbo

go build -o=./bin/cvcamera -tags=cv4,jpeg ./cmd/camera

Usage as Server

Usage of camera:
  -bind string
	Bind address (default ":56000")
  -delay int
	Delay between frames, in milliseconds (default 10)
  -width float
	Frame width (default 640)
  -height float
	Frame height (default 480)
  -index int
	Camera index
  -model string
    saved_mode path
  -db string
    classifier db

User as lib

import (
    "log"

	"github.com/llgcode/draw2d"

    "github.com/bububa/facenet"
)

func main() {
    estimator, err := facenet.New(
        facenet.WithModel("./models/facenet"),
        facenet.WithDB("./models/people.db"),
        facenet.WithFontPath("./font"),
    )
    if err != nil {
       log.Fatalln(err)
    }
	err = estimator.SetFont(&draw2d.FontData{
		Name: "NotoSansCJKsc",
		//Name:   "Roboto",
		Family: draw2d.FontFamilySans,
		Style:  draw2d.FontStyleNormal,
	}, 9)
	if err != nil {
		log.Fatalln(err)
	}

    // Delete labels
    {
        labels := []string{"xxx", "yyy"}
        for _, label := range labels {
            if deleted := estimator.DeletePerson(label); deleted {
                log.Printf("[INFO] person: %s deleted\n", label)
                continue
            }
            log.Printf("[WRN] person: %s not found\n", label)
        }
        err := estimator.SaveDB("./models/people.db")
        if err != nil {
            log.Fatalln(err)
        }
    }

    // Detect faces
    {
        img, _ := loadImage(imgPath)
        minSize := 20
		markers, err := instance.DetectFaces(img, minSize)
		if err != nil {
			log.Fatalln(err)
		}
		for _, marker := range markers.Markers() {
			if marker.Error() != nil {
				log.Printf("label: %s, %v\n", marker.Label(), marker.Error())
			} else {
				log.Printf("label: %s, distance:%f\n", marker.Label(), marker.Distance())
			}
		}
		if outputPath != "" {
            txtColor := "#FFF"
            successColor := "#4CAF50"
            failedColor := "#F44336"
            strokeWidth := 2
            successMarkerOnly := false
			markerImg := estimator.DrawMarkers(markers, txtColor, successColor, failedColor, 2, successMarkerOnly)
			if err := saveImage(markerImg, outputPath); err != nil {
				log.Fatalln(err)
			}
		}
    }

    // Training
    // check cmd/facenet
}
Similar Resources

Ensembles of decision trees in go/golang.

Ensembles of decision trees in go/golang.

CloudForest Google Group Fast, flexible, multi-threaded ensembles of decision trees for machine learning in pure Go (golang). CloudForest allows for a

Dec 1, 2022

Genetic Algorithms library written in Go / golang

Description Genetic Algorithms for Go/Golang Install $ go install git://github.com/thoj/go-galib.git Compiling examples: $ git clone git://github.com

Sep 27, 2022

Golang Genetic Algorithm

Golang Genetic Algorithm

goga Golang implementation of a genetic algorithm. See ./examples for info on how to use the library. Overview Goga is a genetic algorithm solution wr

Dec 19, 2022

Golang Neural Network

Golang Neural Network

Varis Neural Networks with GO About Package Some time ago I decided to learn Go language and neural networks. So it's my variation of Neural Networks

Sep 27, 2022

Golang implementation of the Paice/Husk Stemming Algorithm

##Golang Implementation of the Paice/Husk stemming algorithm This project was created for the QUT course INB344. Details on the algorithm can be found

Sep 27, 2022

Golang HTML to PDF Converter

Golang HTML to PDF Converter

Golang HTML to PDF Converter For reading any document, one prefers PDF format over any other formats as it is considered as a standard format for any

Dec 15, 2022

A high-performance timeline tracing library for Golang, used by TiDB

Minitrace-Go A high-performance, ergonomic timeline tracing library for Golang. Basic Usage package main import ( "context" "fmt" "strcon

Nov 28, 2022

Gota: DataFrames and data wrangling in Go (Golang)

Gota: DataFrames, Series and Data Wrangling for Go This is an implementation of DataFrames, Series and data wrangling methods for the Go programming l

Jan 5, 2023

Golang k-d tree implementation with duplicate coordinate support

Golang k-d tree implementation with duplicate coordinate support

Nov 9, 2022
Tensorflow + Go, the gopher way
Tensorflow + Go, the gopher way

tfgo: TensorFlow in Go tfgo: TensorFlow in Go Dependencies Installation Getting started Computer Vision using data flow graph Train in Python, Serve i

Jan 1, 2023
Go binding for TensorFlow Lite
Go binding for TensorFlow Lite

go-tflite Go binding for TensorFlow Lite Usage model := tflite.NewModelFromFile("sin_model.tflite") if model == nil { log.Fatal("cannot load model")

Jan 1, 2023
Genetic algorithms using Golang Generics

Package genetic Package genetic implements genetic algorithms using Golang's Gen

Sep 23, 2022
Go package for OCR (Optical Character Recognition), by using Tesseract C++ library

gosseract OCR Golang OCR package, by using Tesseract C++ library. OCR Server Do you just want OCR server, or see the working example of this package?

Jan 3, 2023
Spice.ai is an open source, portable runtime for training and using deep learning on time series data.
Spice.ai is an open source, portable runtime for training and using deep learning on time series data.

Spice.ai Spice.ai is an open source, portable runtime for training and using deep learning on time series data. ⚠️ DEVELOPER PREVIEW ONLY Spice.ai is

Dec 15, 2022
Incentivized AI Training Casino using ISCP for the Agri-D Hackaton!
Incentivized AI Training Casino using ISCP for the Agri-D Hackaton!

Welcome to the Wasp repository! Wasp is a node software developed by the IOTA Foundation to run the IOTA Smart Contract Protocol (ISCP in short) on to

May 15, 2022
Advent of Code 2016 in Go using only GitHub Copilot

Advent of Gopilot Solutions to Advent of Code 2016 in Go using only GitHub Copilot. "Rules" The idea is to have GitHub Copilot generate all the actual

Nov 16, 2021
Simple gc using integer vectors to simulate

gcint Simple gc using integer vectors to simulate Iterate primarily over what should be the shorter vector (readers) removing unused references in fro

Nov 24, 2021
Bcfm-study-case - A simple http server using the Echo library in Go language
Bcfm-study-case - A simple http server using the Echo library in Go language

Task 1 Hakkında Burada Go dilinde Echo kütüphanesini kullanarak basit bir http s

Feb 2, 2022
Naive Bayesian Classification for Golang.

Naive Bayesian Classification Perform naive Bayesian classification into an arbitrary number of classes on sets of strings. bayesian also supports ter

Dec 30, 2022