ncs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2018 License: Apache-2.0 Imports: 2 Imported by: 7

README

go-ncs

This package contains Go language bindings for the Intel® Movidius™ Neural Compute Stick (NCS) (https://developer.movidius.com/).

You must have the Intel Movidius NCS hardware in order to use this package.

Install

Install the Movidius Neural Compute SDK

This package has only been tested on Ubuntu 16.04 LTS.

First, install the Movidius Neural Compute SDK from https://github.com/movidius/ncsdk

git clone https://github.com/movidius/ncsdk.git
cd ncsdk
make install

Once you have installed the SDK you can then download and compile the graph files for the Caffe GoogLeNet example by running the following commands:

cd ./examples/caffe/GoogLeNet
make prototxt
make caffemodel
make compile

This will download and compile the NCS graph file needed to run the go-ncs examples.

Install the go-ncs Go package

Now you can install the go-ncs Go package:

go get -d -u github.com/hybridgroup/go-ncs

Once you have installed go-ncs you can use it just like any other Golang package.

Using

Here is a very simple example of opening/closing a connection to an NCS stick:

package main

import (
	"fmt"

	ncs "github.com/hybridgroup/go-ncs"
)

func main() {
	res, name := ncs.GetDeviceName(0)
	if res != ncs.StatusOK {
		fmt.Printf("NCS Error: %v\n", res)
		return
	}

	fmt.Println("NCS: " + name)

	// open device
	fmt.Println("Opening NCS device " + name + "...")
	res, stick := ncs.OpenDevice(name)
	if res != ncs.StatusOK {
		fmt.Printf("NCS Error: %v\n", res)
		return
	}

	// close device
	fmt.Println("Closing NCS device " + name + "...")
	res = stick.CloseDevice()
	if res != ncs.StatusOK {
		fmt.Printf("NCS Error: %v\n", res)
		return
	}
}

There are several examples in the cmd directory of this repository.

Using go-ncs with GoCV

It is very useful to combine go-ncs with GoCV (https://gocv.io) to be able to use the video capture and processing abilities of GoCV along with the classification abilities of the NCS. Take a look at the cmd\caffe and cmd\caffe-video for examples.

License

Licensed under the Apache 2.0 license. Copyright (c) 2018 The Hybrid Group.

Documentation

Overview

Package ncs is a Go language wrapper for the Intel® Movidius™ Neural Compute Stick (NCS)

For more information go to: https://developer.movidius.com/

You must have the Intel Movidius NCS hardware in order to use this package.

Index

Constants

View Source
const (
	// StatusOK when the device is OK.
	StatusOK = 0

	// StatusBusy means device is busy, retry later.
	StatusBusy = -1

	// StatusError communicating with the device.
	StatusError = -2

	// StatusOutOfMemory means device out of memory.
	StatusOutOfMemory = -3

	// StatusDeviceNotFound means no device at the given index or name.
	StatusDeviceNotFound = -4

	// StatusInvalidParameters when at least one of the given parameters is wrong.
	StatusInvalidParameters = -5

	// StatusTimeout in the communication with the device.
	StatusTimeout = -6

	// StatusCmdNotFound means the file to boot Myriad was not found.
	StatusCmdNotFound = -7

	// StatusNoData means no data to return, call LoadTensor first.
	StatusNoData = -8

	// StatusGone means the graph or device has been closed during the operation.
	StatusGone = -9

	// StatusUnsupportedGraphFile means the graph file version is not supported.
	StatusUnsupportedGraphFile = -10

	// StatusMyriadError when an error has been reported by the device, use MVNC_DEBUG_INFO.
	StatusMyriadError = -11
)

Variables

This section is empty.

Functions

func OpenDevice

func OpenDevice(name string) (Status, *Stick)

OpenDevice initializes an NCS device and returns a Stick.

For more information: https://movidius.github.io/ncsdk/c_api/mvncOpenDevice.html

Types

type Graph

type Graph struct {
	GraphHandle unsafe.Pointer
}

Graph

func (*Graph) DeallocateGraph

func (g *Graph) DeallocateGraph() Status

DeallocateGraph deallocates and frees resources for a Graph.

For more information: https://movidius.github.io/ncsdk/c_api/mvncDeallocateGraph.html

func (*Graph) GetResult

func (g *Graph) GetResult() (Status, []byte)

GetResult retrieves the result of an inference that was previously initiated using the LoadTensor() method.

For more information: https://movidius.github.io/ncsdk/c_api/mvncGetResult.html

func (*Graph) LoadTensor

func (g *Graph) LoadTensor(tensorData []byte) Status

LoadTensor starts inference on the NCS by providing input to the neural network.

For more information: https://movidius.github.io/ncsdk/c_api/mvncLoadTensor.html

type Status

type Status int

Status is the device status

func GetDeviceName

func GetDeviceName(index int) (Status, string)

GetDeviceName gets the name of the NCS stick located at index.

For more information: https://movidius.github.io/ncsdk/c_api/mvncGetDeviceName.html

type Stick

type Stick struct {
	DeviceHandle unsafe.Pointer
}

Stick

func (*Stick) AllocateGraph

func (s *Stick) AllocateGraph(graphData []byte) (Status, *Graph)

AllocateGraph allocates a graph for use on an NCS device, and returns a Graph.

For more information: https://movidius.github.io/ncsdk/c_api/mvncAllocateGraph.html

func (*Stick) CloseDevice

func (s *Stick) CloseDevice() Status

CloseDevice closes a previously opened NCS device.

For more information: https://movidius.github.io/ncsdk/c_api/mvncCloseDevice.html

Directories

Path Synopsis
cmd
caffe
How to use: You must have OpenCV/GoCV installed to use this example.
How to use: You must have OpenCV/GoCV installed to use this example.
caffe-video
How to use: This example opens a connection to a Movidius Neural Computer Stick (NCS) then uses OpenCV to open a camera, and start displaying the current classification of whatever the camera sees.
How to use: This example opens a connection to a Movidius Neural Computer Stick (NCS) then uses OpenCV to open a camera, and start displaying the current classification of whatever the camera sees.

Jump to

Keyboard shortcuts

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