godd

package module
Version: v0.0.0-...-ae5a168 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 6 Imported by: 0

README

forthebadgeforthebadge

Build Status Go Report Card Codacy Badge GoDoc

GoDD

🧠 DeepDetect package for easy integration in any Go project

GoDD offer a simple way to use DeepDetect in your Go software, by providing a simple interface to communicate with the different API endpoints supported by DeepDetect.

GoDD currrently only support prediction, not training.

Install

go get -u github.com/jolibrain/godd

Examples

DeepDetect quickstart with Docker:

docker pull beniz/deepdetect_cpu

docker run -d -p 8080:8080 -v $HOME/deepdetect-models:/opt/my-models beniz/deepdetect_cpu

wget https://deepdetect.com/models/voc0712_dd.tar.gz

sudo mkdir -p $HOME/deepdetect-models/voc0712 && sudo tar -xvf voc0712_dd.tar.gz -C $HOME/deepdetect-models/voc0712


Get informations on a DeepDetect instance:

// Set DeepDetect host informations
const myDD = "127.0.0.1:8080"

// Retrieve informations
info, err := godd.GetInfo(myDD)
if err != nil {
	fmt.Println(err.Error())
	os.Exit(1)
}

// Display informations
fmt.Println(info)

// Display only the services field
fmt.Println(info.Head.Services)

Create a service:

// Create a service request structure
var service godd.ServiceRequest

// Specify values for your service creation
service.Name = "imageserv"
service.Description = "object detection service"
service.Type = "supervised"
service.Mllib = "caffe"
service.Parameters.Input.Connector = "image"
service.Parameters.Input.Width = 300
service.Parameters.Input.Height = 300
service.Parameters.Mllib.Nclasses = 21
service.Model.Repository = "/opt/my-models/voc0712/"

// Send the service creation request
creationResult, err := godd.CreateService(myDD, &service)
if err != nil {
	log.Fatal(err)
}

// Check if the service is created
if creationResult.Status.Code == 200 {
	fmt.Println("Service creation: " + creationResult.Status.Msg)
} else {
	fmt.Println("Service creation: " + creationResult.Status.Msg)
}

Predict:

// Create predict structure for request parameters
var predict godd.PredictRequest

// Specify values for your prediction
predict.Service = "imageserv"
predict.Data = append(predict.Data, "https://t2.ea.ltmcdn.com/fr/images/9/0/0/les_bienfaits_d_avoir_un_chien_1009_600.jpg")
predict.Parameters.Output.Bbox = true
predict.Parameters.Output.ConfidenceThreshold = 0.1

// Execute the prediction
predictResult, err := godd.Predict(myDD, &predict)
if err != nil {
	log.Fatal(err)
}

// Print data of the first object detected
if predictResult.Status.Code == 200 {
	// Print the complete JSON result:
	// fmt.Println(string(predictResult))
	fmt.Println("Category: " + predictResult.Body.Predictions[0].Classes[0.Cat)
	fmt.Println("Probability: " + strconv.FormatFloa(predictResult.Body.Predictions[0].Classes[0].Prob, 'f', 6, 64))
	var bbox, _ = json.Marshal(predictResult.Body.Predictions[0].Classes[0.Bbox)
	fmt.Println("Bbox: " + string(bbox))
} else {
	fmt.Println("Prediction failed: " + predictResult.Status.Msg)
}

Delete a service:

// Delete service
serviceDeleteStatus, err := godd.DeleteService(myDD, "imageserv")
if err != nil {
	log.Fatal(err)
}

fmt.Println("Service deletion:")
fmt.Println(serviceDeleteStatus)

You can see the full examples in the examples folder.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Status struct {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
	} `json:"status"`
	Head struct {
		Method   string `json:"method"`
		Version  string `json:"version"`
		Branch   string `json:"branch"`
		Commit   string `json:"commit"`
		Services []struct {
			Mltype      string `json:"mltype"`
			Name        string `json:"name"`
			Description string `json:"description"`
			Mllib       string `json:"mllib"`
			Predict     bool   `json:"predict"`
		} `json:"services"`
	} `json:"head"`
}

Info structure contain informations fetched by the GetInfo function

func GetInfo

func GetInfo(host string) (info *Info, err error)

GetInfo return an object containing informations from /info

type PredictRequest

type PredictRequest struct {
	// General parameters
	Service    string   `json:"service,omitempty"`
	Data       []string `json:"data,omitempty"`
	Parameters struct {
		Input struct {
			// Image - image
			Width      int     `json:"width,omitempty"`
			Height     int     `json:"height,omitempty"`
			CropWidth  int     `json:"crop_width,omitempty"`
			CropHeight int     `json:"crop_height,omitempty"`
			BW         bool    `json:"bw,omitempty"`
			MeanTF     float64 `json:"mean,omitempty"`
			Mean       []int   `json:"mean,omitempty"`
			STD        float64 `json:"std,omitempty"`
			// CSV - csv
			Ignore    []string  `json:"ignore,omitempty"`
			Separator string    `json:"separator,omitempty"`
			ID        string    `json:"id,omitempty"`
			Scale     bool      `json:"scale,omitempty"`
			MinVals   []float64 `json:"min_vals,omitempty"`
			MaxVals   []float64 `json:"max_vals,omitempty"`
			// MISSING: categoricals_mapping
			// Text - txt
			Count         int    `json:"count,omitempty"`
			MinCount      int    `json:"min_count,omitempty"`
			MinWordLength int    `json:"min_word_length,omitempty"`
			TFIDF         bool   `json:"tfidf,omitempty"`
			Sentences     bool   `json:"sentences,omitempty"`
			Characters    bool   `json:"characters,omitempty"`
			Sequence      int    `json:"sequence,omitempty"`
			ReadForward   bool   `json:"read_forward,omitempty"`
			Alphabet      string `json:"alphabet,omitempty"`
			Sparse        bool   `json:"sparse,omitempty"`
		} `json:"input,omitempty"`
		Output struct {
			Best     int    `json:"best,omitempty"`
			Template string `json:"template,omitempty"`
			Network  *struct {
				URL         string `json:"url,omitempty"`
				HTTPMethod  string `json:"http_method,omitempty"`
				ContentType string `json:"content_type,omitempty"`
			} `json:"network,omitempty"`
			Measure             []float64 `json:"measure,omitempty"`
			ConfidenceThreshold float64   `json:"confidence_threshold,omitempty"`
			Bbox                bool      `json:"bbox,omitempty"`
			Mask                bool      `json:"mask,omitempty"`
			Rois                string    `json:"rois,omitempty"`
			Index               bool      `json:"index,omitempty"`
			BuildIndex          bool      `json:"build_index,omitempty"`
			Search              bool      `json:"search,omitempty"`
			MultiboxRois        bool      `json:"multibox_rois,omitempty"`
			CTC                 bool      `json:"ctc,omitempty"`
		} `json:"output,omitempty"`
		Mllib struct {
			// Caffe / Caffe2
			GPU          bool   `json:"gpu,omitempty"`
			GPUID        []int  `json:"gpuid,omitempty"`
			ExtractLayer string `json:"extract_layer,omitempty"`
			// Net or TF
			TestBatchSize int `json:"test_batch_size,omitempty"`
			// Tensorflow
			InputLayer  string `json:"inputlayer,omitempty"`
			OutputLayer string `json:"outputlayer,omitempty"`
		} `json:"mllib,omitempty"`
	} `json:"parameters,omitempty"`
}

PredictRequest hold data for the prediction request

type PredictResult

type PredictResult struct {
	Status struct {
		Code int    `json:"code,omitempty"`
		Msg  string `json:"msg,omitempty"`
	} `json:"status,omitempty"`
	Head struct {
		Method  string  `json:"method,omitempty"`
		Service string  `json:"service,omitempty"`
		Time    float64 `json:"time,omitempty"`
	} `json:"head,omitempty"`
	Body struct {
		Predictions []struct {
			Classes []struct {
				Prob float64 `json:"prob,omitempty"`
				Last bool    `json:"last,omitempty"`
				Bbox struct {
					Ymax float64 `json:"ymax,omitempty"`
					Xmax float64 `json:"xmax,omitempty"`
					Ymin float64 `json:"ymin,omitempty"`
					Xmin float64 `json:"xmin,omitempty"`
				} `json:"bbox,omitempty"`
				Mask struct {
					Format string `json:"format,omitempty"`
					Width  int    `json:"width,omitempty"`
					Height int    `json:"height,omitempty"`
					Data   []int  `json:"data,omitempty"`
				} `json:"mask,omitempty"`
				Cat string `json:"cat,omitempty"`
			}
			URI string `json:"uri,omitempty"`
		} `json:"predictions,omitempty"`
	} `json:"body,omitempty"`
}

PredictResult struct storing predictions result

func Predict

func Predict(host string, predictRequest *PredictRequest) (result PredictResult, err error)

Predict perform a /predict call and return a PredictResult structure

type ServiceInfo

type ServiceInfo struct {
	Status struct {
		Code int    `json:"code,omitempty"`
		Msg  string `json:"msg,omitempty"`
	} `json:"status,omitempty"`
	Body struct {
		Mllib       string `json:"mllib,omitempty"`
		Description string `json:"description,omitempty"`
		Name        string `json:"name,omitempty"`
		Jobs        []struct {
			Job    int    `json:"job,omitempty"`
			Status string `json:"status,omitempty"`
		} `json:"jobs,omitempty"`
	} `json:"body,omitempty"`
}

ServiceInfo structure contain informations fetched by the GetServiceInfo function

func GetServiceInfo

func GetServiceInfo(host string, service string) (info *ServiceInfo, err error)

GetServiceInfo fetch service informations using the /services/<service_name> endpoint It takes the host and the service name as input, and return a *ServiceInfo structure.

type ServiceRequest

type ServiceRequest struct {
	// General parameters
	Name        string
	Mllib       string `json:"mllib,omitempty"`
	Type        string `json:"type,default=supervised"`
	Description string `json:"description,omitempty"`
	// Model
	Model struct {
		Repository       string   `json:"repository,omitempty"`
		Templates        string   `json:"templates,omitempty"`
		Init             string   `json:"init,omitempty"`
		Weights          string   `json:"weights,omitempty"`
		CreateRepository bool     `json:"create_repository,omitempty"`
		IndexPreload     bool     `json:"index_preload,omitempty"`
		Extensions       []string `json:"extensions,omitempty"`
	} `json:"model,omitempty"`
	Parameters struct {
		Input struct {
			// Input
			Connector string `json:"connector,omitempty"`
			// Input - image
			Width         int       `json:"width,omitempty"`
			Height        int       `json:"height,omitempty"`
			BW            bool      `json:"bw,omitempty"`
			MeanTS        float64   `json:"mean,omitempty"`
			Mean          []float64 `json:"mean,omitempty"`
			STD           float64   `json:"std,omitempty"`
			Segmentation  bool      `json:"segmentation,omitempty"`
			MultiLabel    bool      `json:"multi_label,omitempty"`
			RootFolder    string    `json:"root_folder,omitempty"`
			CTC           bool      `json:"ctc,omitempty"`
			UnchangedData bool      `json:"unchanged_data,omitempty"`
			Bbox          bool      `json:"bbox,omitempty"`
			// Input - CSV
			Label        string   `json:"label,omitempty"`
			Ignore       []string `json:"ignore,omitempty"`
			LabelOffset  int      `json:"label_offset,omitempty"`
			Separator    string   `json:"separator,omitempty"`
			ID           string   `json:"id,omitempty"`
			Scale        bool     `json:"scale,omitempty"`
			Categoricals []string `json:"categoricals,omitempty"`
			DB           bool     `json:"db,omitempty"`
			// Input - TXT
			Sentences   bool   `json:"sentences,omitempty"`
			Characters  bool   `json:"characters,omitempty"`
			Sequence    int    `json:"sequence,omitempty"`
			ReadForward bool   `json:"read_forward,omitempty"`
			Alphabet    string `json:"alphabet,omitempty"`
			Sparse      bool   `json:"sparse,omitempty"`
		} `json:"input,omitempty"`
		Mllib struct {
			// Caffe and Caffe2
			Nclasses           int      `json:"nclasses,omitempty"`
			Ntargets           int      `json:"ntargets,omitempty"`
			GPU                bool     `json:"gpu,omitempty"`
			GPUID              []int    `json:"gpuid,omitempty"`
			Template           string   `json:"template,omitempty"`
			LayersMLP          []int    `json:"layers,omitempty"`
			LayersConvnet      []string `json:"layers,omitempty"`
			Activation         string   `json:"activation,omitempty"`
			Dropout            float64  `json:"dropout,omitempty"`
			Regression         bool     `json:"regression,omitempty"`
			Autoencoder        bool     `json:"autoencoder,omitempty"`
			CropSize           int      `json:"crop_size,omitempty"`
			Rotate             bool     `json:"rotate,omitempty"`
			Mirror             bool     `json:"mirror,omitempty"`
			Finetuning         bool     `json:"finetuning,omitempty"`
			DB                 bool     `json:"db,omitempty"`
			ScalingTemperature float64  `json:"scaling_temperature,omitempty"`
			Loss               string   `json:"loss,omitempty"`
			// Noise - images only
			Prob         float64 `json:"prob,omitempty"`
			AllEffects   bool    `json:"all_effects,omitempty"`
			Decolorize   bool    `json:"decolorize,omitempty"`
			HistEQ       bool    `json:"hist_eq,omitempty"`
			Inverse      bool    `json:"inverse,omitempty"`
			GaussBlur    bool    `json:"gauss_blur,omitempty"`
			Posterize    bool    `json:"posterize,omitempty"`
			Erode        bool    `json:"erode,omitempty"`
			Saltpepper   bool    `json:"saltpepper,omitempty"`
			Clahe        bool    `json:"clahe,omitempty"`
			ConvertToHSV bool    `json:"convert_to_hsv,omitempty"`
			ConvertToLAB bool    `json:"convert_to_lab,omitempty"`
			// Distort - images only
			Brightness     bool `json:"brightness,omitempty"`
			Contrast       bool `json:"contrast,omitempty"`
			Saturation     bool `json:"saturation,omitempty"`
			HUE            bool `json:"HUE,omitempty"`
			RandomOrdering bool `json:"random ordering,omitempty,omitempty"`
			// TensorFlow
			InputLayer  string `json:"inputlayer,omitempty"`
			OutputLayer string `json:"outputlayer,omitempty"`
			// Memory
			Datatype         string `json:"datatype,omitempty"`
			MaxBatchSize     int    `json:"maxBatchSize,omitempty"`
			MaxWorkspaceSize int    `json:"maxWorkspaceSize,omitempty"`
		} `json:"mllib,omitempty"`
		Output struct {
			StoreConfig bool `json:"store_config,omitempty"`
		} `json:"output,omitempty"`
	} `json:"parameters,omitempty"`
}

ServiceRequest hold data for the service creation request See: https://deepdetect.com/api/#create-a-service

type Status

type Status struct {
	Status struct {
		Code int    `json:"code,omitempty"`
		Msg  string `json:"msg,omitempty"`
	} `json:"status,omitempty"`
}

Status struct storing requests execution results

func CreateService

func CreateService(host string, service *ServiceRequest) (result *Status, err error)

CreateService create a service using the /services endpoint, it takes the host and a *ServiceRequest as input and return a *CreationResult structure.

func DeleteService

func DeleteService(host string, service string) (status *Status, err error)

DeleteService delete a service using the /services/<service_name> endpoint, it takes the host and a service name as input and return a *Status structure.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL