yolo

package
v0.0.0-...-79a5ab8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConfidenceThreshold

func WithConfidenceThreshold(threshold float32) func(*DetectOptions)

WithConfidenceThreshold sets the confidence threshold for detections

func WithCpuMemArena

func WithCpuMemArena() func(*DetectorOptions)

WithCpuMemArena enables CPU memory arena

func WithInterOpThreads

func WithInterOpThreads(threads int) func(*DetectorOptions)

WithInterOpThreads sets the number of inter-op threads

func WithIntraOpThreads

func WithIntraOpThreads(threads int) func(*DetectorOptions)

WithIntraOpThreads sets the number of intra-op threads

func WithIoUThreshold

func WithIoUThreshold(threshold float32) func(*DetectOptions)

WithIoUThreshold sets the IoU threshold for NMS

func WithMemPattern

func WithMemPattern() func(*DetectorOptions)

WithMemPattern enables memory pattern optimization

func WithProvider

func WithProvider(provider *ProviderOptions) func(*DetectorOptions)

WithProvider sets the execution provider options

Types

type Box

type Box struct {
	X1 float32 `json:"x1"` // Top-left corner X coordinate
	Y1 float32 `json:"y1"` // Top-left corner Y coordinate
	X2 float32 `json:"x2"` // Bottom-right corner X coordinate
	Y2 float32 `json:"y2"` // Bottom-right corner Y coordinate
}

Box represents a bounding box with normalized coordinates

type DetectOptions

type DetectOptions struct {
	ConfidenceThreshold float32 `json:"confidence_threshold"` // Confidence threshold for detections
	IoUThreshold        float32 `json:"iou_threshold"`        // IoU threshold for NMS
}

DetectOptions contains options for object detection

type Detection

type Detection struct {
	Class      int     `json:"class"`      // Class index
	Label      string  `json:"label"`      // Class label
	Confidence float32 `json:"confidence"` // Confidence score
	Box        Box     `json:"box"`        // Bounding box
}

Detection represents a single object detection result

func (Detection) DrawBox

func (det Detection) DrawBox(img *image.RGBA, color color.RGBA)

DrawBox draws the bounding box on the image

type DetectionResult

type DetectionResult struct {
	Detections      []Detection   `json:"detections"`       // Detected objects
	PreprocessTime  time.Duration `json:"preprocess_time"`  // Preprocessing time
	InferenceTime   time.Duration `json:"inference_time"`   // Inference time
	PostprocessTime time.Duration `json:"postprocess_time"` // Postprocessing time
	DetectionTime   time.Duration `json:"detection_time"`   // Total detection time
}

DetectionResult represents a single object detection result

func (*DetectionResult) String

func (r *DetectionResult) String() string

String returns a human-readable summary of the detection results

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector manages the YOLO object detection model

func NewDetector

func NewDetector(modelPath string, opts ...func(*DetectorOptions)) (*Detector, error)

NewDetector creates a new YOLO detector instance

func (*Detector) Close

func (d *Detector) Close() error

Close releases all resources associated with the detector

func (*Detector) Detect

func (d *Detector) Detect(img image.Image, opts ...func(*DetectOptions)) (*DetectionResult, error)

Detect performs object detection on the provided image

type DetectorOptions

type DetectorOptions struct {
	ModelPath      string           // Path to the ONNX model file
	InterOpThreads int              // Number of inter-op threads
	IntraOpThreads int              // Number of intra-op threads
	CpuMemArena    bool             // Enable CPU memory arena
	MemPattern     bool             // Enable memory pattern optimization
	Provider       *ProviderOptions // Execution provider options
}

DetectorOptions contains options for creating a new detector

type ProviderOptions

type ProviderOptions struct {
	Provider ProviderType

	// CUDA specific options
	CUDADeviceID   int
	CUDAArenaSize  int64
	CUDAStreamSize int64

	// CoreML specific options
	CoreMLFlags uint32

	// TensorRT specific options
	TensorRTDeviceID  int
	TensorRTWorkspace int64
	TensorRTOptLevel  int

	// DirectML specific options
	DirectMLDeviceID int
}

ProviderOptions holds configuration for different execution providers

func DefaultProviderOptions

func DefaultProviderOptions() *ProviderOptions

DefaultProviderOptions returns ProviderOptions with sensible defaults

type ProviderType

type ProviderType int

ProviderType represents different execution providers

const (
	ProviderCPU ProviderType = iota
	ProviderCUDA
	ProviderCoreML
	ProviderDirectML
	ProviderTensorRT
)

Jump to

Keyboard shortcuts

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