www.gusucode.com > vision 源码程序 matlab案例代码 > vision/LoadNetworkInRCNNObjectDetectorExample.m
%% Use A Saved Network In R-CNN Object Detector % Create an R-CNN object detector and set it up to use a saved network % checkpoint. A network checkpoint is saved every epoch during network % training when the |trainingOptions| 'CheckpointPath' parameter is set. % Network checkpoints are useful in case your training session terminates % unexpectedly. %% % Load the stop sign training data. load('rcnnStopSigns.mat','stopSigns','layers') %% % Add full path to image files. stopSigns.imageFilename = fullfile(toolboxdir('vision'),'visiondata', ... stopSigns.imageFilename); %% % Set the 'CheckpointPath' using the |trainingOptions| function. checkpointLocation = tempdir; options = trainingOptions('sgdm','Verbose',false, ... 'CheckpointPath',checkpointLocation); %% % Train the R-CNN object detector with a few images. rcnn = trainRCNNObjectDetector(stopSigns(1:3,:),layers,options); %% % Load a saved network checkpoint. wildcardFilePath = fullfile(checkpointLocation,'convnet_checkpoint__*.mat'); contents = dir(wildcardFilePath); %% % Load one of the checkpoint networks. filepath = fullfile(contents(1).folder,contents(1).name); checkpoint = load(filepath); checkpoint.net %% % Create a new R-CNN object detector and set it up to use the saved % network. rcnnCheckPoint = rcnnObjectDetector(); rcnnCheckPoint.RegionProposalFcn = @rcnnObjectDetector.proposeRegions; %% % Set the Network to the saved network checkpoint. rcnnCheckPoint.Network = checkpoint.net