tensorflowutils

package module
v0.0.0-...-4e22a36 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: MIT Imports: 9 Imported by: 0

README

go-tensorflow-utilities

Utility functions for image recognition with tensorflow, using golang.

Install

 $ go get github.com/CombatMage/go-tensorflow-utilities

Documentation

Is available on godoc:

https://godoc.org/github.com/CombatMage/go-tensorflow-utilities

Reference

Credit goes to Build an Image Recognition API with Go and TensorFlow.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeTensorFromImage

func MakeTensorFromImage(imageBuffer *bytes.Buffer, imageFormat ImageType) (*tf.Tensor, error)

MakeTensorFromImage converts the given image (as a byte.Buffer) into a tensor. Currently png and jpg is supported as image formats.

Types

type ImageType

type ImageType string

ImageType represents the type of an image, used by MakeTensorFromImage().

const (
	// PNG is a predefined type for MakeTensorFromImage().
	PNG ImageType = "PNG"
	// JPG is a predefined type for MakeTensorFromImage().
	JPG ImageType = "JPG"
)

type Label

type Label struct {
	Label       string
	Probability float32
}

Label represents a classified label with its propability.

type Model

type Model struct {
	SessionModel *tf.Session
	GraphModel   *tf.Graph
	Labels       []string
}

Model represents a loaded tensorflow graph model with it's labels an the generated sessionModel for this graph.

func NewModel

func NewModel(modelFile string, lableFile string) (*Model, error)

NewModel loads graphModel and label from given filepath and returns a new Model, containing the Graph, it's labels and the session. It is assumed that the labels are separated by newlines.

func (*Model) ClassifyImage

func (model *Model) ClassifyImage(imageBuffer *bytes.Buffer, imageFormat ImageType) ([]Label, error)

ClassifyImage tries to classify the given image with the help of this model and returns possible labels with a propability for each label.

func (*Model) Run

func (model *Model) Run(tensor *tf.Tensor) ([]*tf.Tensor, error)

Run evaluates the given tensor with this model and returns the result.

Jump to

Keyboard shortcuts

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