gofaces

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2019 License: Apache-2.0 Imports: 13 Imported by: 1

README

gofaces

This repository is an implementation of this article.

It is a toy to run face detection on a picture with a neural network.

The neural network is based on Tiny YOLO v2 and is encoded in the onnx format. It decocded with onnx-go and executed by Gorgonia.

Installation an usage

Requirements

  • Go with modules support, 1.12+ recommended.
  • Git LFS. It's needed in order to get the file model.onnx when cloning the repo. If you don’t have this, running will fail with an error: proto: can’t skip unknown wire type 6

Usage

git clone https://github.com/owulveryck/gofaces
cd gofaces
git lfs install
git lfs fetch
git lfs checkout model/model.onnx
cd cmd
go run main.go -h

Documentation

Overview

Package gofaces is a set of functions to handle the input and output of a Tint YOLO v2 model.

Index

Constants

View Source
const (
	// HSize is the height of the input picture
	HSize = 416
	// WSize is the width of the input picture
	WSize = 416
)

Variables

This section is empty.

Functions

func GetTensorFromImage

func GetTensorFromImage(r io.Reader) (tensor.Tensor, error)

GetTensorFromImage reads an image from r and returns a tensor suitable to run in tiny yolo. The tensor is BWHC and is normalized; its shape is (1,wSize,hSize,3)

Types

type Box

type Box struct {
	R image.Rectangle

	Confidence float64 // The confidence the model has that there is at least one element in this box
	Elements   []Element
	// contains filtered or unexported fields
}

Box is holding a bounding box A bunding box is a rectangle R containing an object with Confidence. The object is one of the Elements (most likely the one with the highest probability)

func ProcessOutput

func ProcessOutput(dense *tensor.Dense) ([]Box, error)

ProcessOutput analyze the tensor dense and output the bouding boxes filled with the predictions

func Sanitize

func Sanitize(boxes []Box) []Box

Sanitize the output from https://medium.com/@jonathan_hui/real-time-object-detection-with-yolo-yolov2-28b1b93e2088

- Sort the predictions by the confidence scores.

- Start from the top scores, ignore any current prediction if we find any previous predictions that have the same class and IoU > 0.5 with the current prediction.

- Repeat step 2 until all predictions are checked.

func (Box) String

func (b Box) String() string

type Element

type Element struct {
	Prob  float64
	Class string
}

Element in a box

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL