mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-05-30 09:26:00 -04:00
Add infrastructure for managing AI object detection models, datasets,
and classes in ZoneMinder.
Database schema (db/AI_Models.sql):
- AI_Datasets: Dataset registry (COCO, ImageNet, etc.)
- AI_Models: Model implementations with framework support
- AI_Object_Classes: Object classes indexed by dataset
- AI_Detection_Settings: Per-monitor detection configuration
- AI_Detections: Detection results with bounding boxes
Pre-populated data (db/coco_dataset.sql):
- COCO 2017 dataset with all 80 object classes
- Default detection settings for person and vehicles
Web UI in Options menu:
- AI Datasets tab: Manage datasets
- AI Models tab: Manage models with framework selection
- AI Classes tab: Manage object classes with dataset filtering
- Modal editors for CRUD operations
- Action handlers with canEdit('System') permission checks
Based on PR #4499.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
81 lines
3.3 KiB
SQL
81 lines
3.3 KiB
SQL
--
|
|
-- Add AI Models tables for ZoneMinder
|
|
--
|
|
|
|
-- AI Datasets table - stores datasets like COCO, ImageNet, etc.
|
|
CREATE TABLE IF NOT EXISTS `AI_Datasets` (
|
|
`Id` int(10) unsigned NOT NULL auto_increment,
|
|
`Name` varchar(64) NOT NULL,
|
|
`Description` TEXT,
|
|
`Version` varchar(32),
|
|
`NumClasses` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`Id`),
|
|
UNIQUE KEY `AI_Datasets_Name_idx` (`Name`)
|
|
) ENGINE=InnoDB;
|
|
|
|
-- AI Models table - stores AI model implementations
|
|
CREATE TABLE IF NOT EXISTS `AI_Models` (
|
|
`Id` int(10) unsigned NOT NULL auto_increment,
|
|
`Name` varchar(64) NOT NULL,
|
|
`Description` TEXT,
|
|
`ModelPath` varchar(255),
|
|
`Framework` enum('TensorFlow','PyTorch','ONNX','OpenVINO','TensorRT','Other') NOT NULL default 'ONNX',
|
|
`Version` varchar(32),
|
|
`DatasetId` int(10) unsigned,
|
|
`Enabled` tinyint(1) unsigned NOT NULL default 0,
|
|
PRIMARY KEY (`Id`),
|
|
UNIQUE KEY `AI_Models_Name_idx` (`Name`),
|
|
FOREIGN KEY (`DatasetId`) REFERENCES `AI_Datasets` (`Id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB;
|
|
|
|
-- AI Object Classes table - stores object classes from datasets
|
|
CREATE TABLE IF NOT EXISTS `AI_Object_Classes` (
|
|
`Id` int(10) unsigned NOT NULL auto_increment,
|
|
`DatasetId` int(10) unsigned NOT NULL,
|
|
`ClassName` varchar(64) NOT NULL,
|
|
`ClassIndex` int(10) unsigned NOT NULL,
|
|
`Description` TEXT,
|
|
PRIMARY KEY (`Id`),
|
|
KEY `AI_Object_Classes_DatasetId_idx` (`DatasetId`),
|
|
UNIQUE KEY `AI_Object_Classes_Dataset_Class_idx` (`DatasetId`, `ClassName`),
|
|
FOREIGN KEY (`DatasetId`) REFERENCES `AI_Datasets` (`Id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB;
|
|
|
|
-- AI Detection Settings table - stores detection settings per monitor and object class
|
|
CREATE TABLE IF NOT EXISTS `AI_Detection_Settings` (
|
|
`Id` int(10) unsigned NOT NULL auto_increment,
|
|
`MonitorId` int(10) unsigned NULL,
|
|
`ObjectClassId` int(10) unsigned NOT NULL,
|
|
`Enabled` tinyint(1) unsigned NOT NULL default 1,
|
|
`ReportDetection` tinyint(1) unsigned NOT NULL default 1,
|
|
`ConfidenceThreshold` tinyint(3) unsigned NOT NULL default 50,
|
|
`BoxColor` varchar(7) NOT NULL default '#FF0000',
|
|
PRIMARY KEY (`Id`),
|
|
KEY `AI_Detection_Settings_MonitorId_idx` (`MonitorId`),
|
|
KEY `AI_Detection_Settings_ObjectClassId_idx` (`ObjectClassId`),
|
|
UNIQUE KEY `AI_Detection_Settings_Monitor_Object_idx` (`MonitorId`, `ObjectClassId`),
|
|
FOREIGN KEY (`MonitorId`) REFERENCES `Monitors` (`Id`) ON DELETE CASCADE,
|
|
FOREIGN KEY (`ObjectClassId`) REFERENCES `AI_Object_Classes` (`Id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB;
|
|
|
|
-- AI Detections table - stores actual detection results
|
|
CREATE TABLE IF NOT EXISTS `AI_Detections` (
|
|
`Id` BIGINT unsigned NOT NULL auto_increment,
|
|
`EventId` BIGINT unsigned NOT NULL,
|
|
`FrameId` BIGINT unsigned,
|
|
`ObjectClassId` int(10) unsigned NOT NULL,
|
|
`Confidence` decimal(5,4) NOT NULL,
|
|
`BoundingBoxX` int(10) unsigned,
|
|
`BoundingBoxY` int(10) unsigned,
|
|
`BoundingBoxWidth` int(10) unsigned,
|
|
`BoundingBoxHeight` int(10) unsigned,
|
|
`DetectedAt` TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3),
|
|
PRIMARY KEY (`Id`),
|
|
KEY `AI_Detections_EventId_idx` (`EventId`),
|
|
KEY `AI_Detections_FrameId_idx` (`FrameId`),
|
|
KEY `AI_Detections_ObjectClassId_idx` (`ObjectClassId`),
|
|
FOREIGN KEY (`EventId`) REFERENCES `Events` (`Id`) ON DELETE CASCADE,
|
|
FOREIGN KEY (`FrameId`) REFERENCES `Frames` (`Id`) ON DELETE SET NULL,
|
|
FOREIGN KEY (`ObjectClassId`) REFERENCES `AI_Object_Classes` (`Id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB;
|