Giter Site home page Giter Site logo

flybird119 / facenet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bububa/facenet

0.0 1.0 0.0 19.97 MB

face detction/recognization golang lib using tensorflow facenet

License: Apache License 2.0

Makefile 0.30% Go 92.64% Smarty 4.61% Python 2.45%

facenet's Introduction

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
}

facenet's People

Contributors

bububa avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.