Documentation ¶
Overview ¶
Package yolov3 provides a Go implementation of the YOLO V3 object detection system: https://pjreddie.com/darknet/yolo/.
The yolov3 package leverages gocv(https://github.com/hybridgroup/gocv) for a neural net able to detect object.
In order for the neural net to be able to detect objects, it needs the pre-trained network model consisting of a .cfg file and a .weights file. Using the Makefile provied by the library, these models can simply be downloaded by running 'make models'.
In order to use the package, make sure you've checked the prerequisites in the README: https://github.com/wimspaargaren/yolov3#prerequisites
Index ¶
Examples ¶
Constants ¶
const ( DefaultInputWidth = 416 DefaultInputHeight = 416 DefaultConfThreshold float32 = 0.5 DefaultNMSThreshold float32 = 0.4 )
Default constants for initialising the yolov3 net.
Variables ¶
This section is empty.
Functions ¶
func DrawDetections ¶ added in v0.2.1
func DrawDetections(frame *gocv.Mat, detections []ObjectDetection)
DrawDetections draws a given list of object detections on a gocv Matrix.
Types ¶
type Config ¶
type Config struct { // InputWidth & InputHeight are used to determine the input size of the image for the network InputWidth int InputHeight int // ConfidenceThreshold can be used to determine the minimum confidence before an object is considered to be "detected" ConfidenceThreshold float32 // Non-maximum suppression threshold used for removing overlapping bounding boxes NMSThreshold float32 // Type on which the network will be executed NetTargetType gocv.NetTargetType NetBackendType gocv.NetBackendType // NewNet function can be used to inject a custom neural net NewNet func(weightsPath, configPath string) ml.NeuralNet }
Config can be used to customise the settings of the neural network used for object detection.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig used to create a working yolov3 net out of the box.
type Net ¶
type Net interface { Close() error GetDetections(gocv.Mat) ([]ObjectDetection, error) GetDetectionsWithFilter(gocv.Mat, map[string]bool) ([]ObjectDetection, error) }
Net the yolov3 net.
func NewNet ¶
NewNet creates new yolo net for given weight path, config and coconames list.
Example ¶
yolov3WeightsPath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/data/yolov3/yolov3.weights") yolov3ConfigPath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/data/yolov3/yolov3.cfg") cocoNamesPath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/data/yolov3/coco.names") yolonet, err := NewNet(yolov3WeightsPath, yolov3ConfigPath, cocoNamesPath) if err != nil { log.WithError(err).Fatal("unable to create yolo net") } // Gracefully close the net when the program is done defer func() { err := yolonet.Close() if err != nil { log.WithError(err).Error("unable to gracefully close yolo net") } }() imagePath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/yolov3/data/example_images/bird.jpg") frame := gocv.IMRead(imagePath, gocv.IMReadColor) detections, err := yolonet.GetDetections(frame) if err != nil { log.WithError(err).Fatal("unable to retrieve predictions") } DrawDetections(&frame, detections) window := gocv.NewWindow("Result Window") defer func() { err := window.Close() if err != nil { log.WithError(err).Error("unable to close window") } }() window.IMShow(frame) window.ResizeWindow(872, 585) window.WaitKey(10000000000)
Output:
func NewNetWithConfig ¶
NewNetWithConfig creates new yolo net with given config.
Example ¶
yolov3WeightsPath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/data/yolov3/yolov3.weights") yolov3ConfigPath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/data/yolov3/yolov3.cfg") cocoNamesPath := path.Join(os.Getenv("GOPATH"), "src/github.com/wimspaargaren/data/yolov3/coco.names") conf := DefaultConfig() // Set the neural net to use CUDA conf.NetBackendType = gocv.NetBackendCUDA conf.NetTargetType = gocv.NetTargetCUDA yolonet, err := NewNetWithConfig(yolov3WeightsPath, yolov3ConfigPath, cocoNamesPath, conf) if err != nil { log.WithError(err).Fatal("unable to create yolo net") } // Gracefully close the net when the program is done defer func() { err := yolonet.Close() if err != nil { log.WithError(err).Error("unable to gracefully close yolo net") } }() // ...
Output:
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
cuda
Package main contains an example on how yo run yolov3 with CUDA.
|
Package main contains an example on how yo run yolov3 with CUDA. |
image
Package main provides an example on how to run yolov3 for a given image.
|
Package main provides an example on how to run yolov3 for a given image. |
webcam
Package main provides an example on how to run yolov3 using a camera.
|
Package main provides an example on how to run yolov3 using a camera. |
internal
|
|
ml
Package ml is used as interface on how a neural network should behave
|
Package ml is used as interface on how a neural network should behave |
ml/mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |