主要内容

火车快速R-CNN停止标志探测器

加载培训数据。

data = load('rcnnstopsigns.mat''stopsigns''fastrcnlayers');stopsigns = data.stopsigns;fastrcnlayers = data.fastrcnlayers;

将满目标添加到图像文件。

stopsigns.imageFilename = fullfile(toolboxdir('想象'),'VisionData'......stopsigns.imagefilename);

随机抽搐数据进行培训。

RNG(0);shuffledidx = randperm(高度(stopsigns));stopsigns = stopsigns(shuffledidx,:);

使用表中的文件创建IMAGEDATASTORE。

imd = imageDatastore (stopSigns.imageFilename);

使用表中的标签列创建BoxLabeldAtastore。

建筑物= boxLabelDatastore (stopSigns(:, 2:结束));

结合数据存储。

DS =联合(IMDS,BLD);

停止标志训练图像有不同的尺寸。预处理数据以将图像和框中调整为预定义大小。

DS =变换(DS,@(数据)预处理数据(数据,[920 968 3]));

设置网络培训选项。

选项=培训选项('sgdm'......'minibatchsize'10,......'italllearnrate',1e-3,......'maxepochs'10,......'checkpoinspath',Tempdir);

培训快速的R-CNN探测器。培训可能需要几分钟才能完成。

frcnn = trainfastrcnnobjectdetector(ds,fastrcnlayers,选项,......'负极的贪婪', 0.1 [0],......'积极透过的',[0.7 1]);
*******************************************************************训练a Fast R-CNN Object Detector for the following object classes: * stopSign --> Extracting region proposals from training datastore...done. Training on single GPU. |=======================================================================================================| | Epoch | Iteration | Time Elapsed | Mini-batch | Mini-batch | Mini-batch | Base Learning | | | | (hh:mm:ss) | Loss | Accuracy | RMSE | Rate | |=======================================================================================================| | 1 | 1 | 00:00:29 | 0.3787 | 93.59% | 0.96 | 0.0010 | | 10 | 10 | 00:05:14 | 0.3032 | 98.52% | 0.95 | 0.0010 | |=======================================================================================================| Detector training complete. *******************************************************************

在测试图像上测试快速R-CNN检测器。

img = imread('stopsigntest.jpg');

运行探测器。

[Bbox,Score,Label] =检测(FRCNN,IMG);

显示检测结果。

detectedimg = InsertObjectAnnotation(IMG,'矩形',bbox,得分);图imshow(detectedimg)

金宝app支持功能

功能Data = PreprocessData(数据,TargetSize)%将图像大小调整为targetsize。scale = targetsize(1:2)./大小(数据{1},[1 2]);数据{1} = IMResize(数据{1},targetsize(1:2));bboxes = round(数据{2});数据{2} = BboxResize(Bboxes,Scale);结尾