A list,

1 introduction Okay… Recently, there are more things and less blog posts, so I decided to make a big news. This blog has recorded in detail the process of vehicle area detection (R-CNN) and vehicle identification (AlexNet) using Matlab. And contains training data sets, test data sets and source code. The training dataset is a Model database from Stanford University that contains 196 different models. Writing here I really want to make fun of the Audi series in this database: many black and white pictures ah hello!! AlexNet data input dimension is 3 when doing training. I found a lot of pictures myself!! … .

2 Environment test environment: Hardware: Intel I5-4590 GTX 980 Software: Matlab R2016b (only this version can achieve RCNN…)

3 Data set download HMM. Train /test: pan.baidu.com/s/1miTn9jy I formatted the data set, changed the images to 227*227, and replaced a few black and white images: http://pan.baidu.com/s/1pKIbQiB then this is what every picture corresponding models of annotation files: pan.baidu.com/s/1nuOR7PR

AlexNet is the 2012 ImageNet contest winner. It has a total of 8 layers, including 5 convolution layers, 2 full connection layers and 1 classification layer. If it is used to carry out forward propagation of an image, then the probability that the final output image belongs to which one of 1000 objects. Here I define AlexNet in Matlab, and this is my code and network structure:

Ii. Source code

clear
clc
 
doTraining = true; % training % decompress data % data = load('./data/carDatasetGroundTruth.mat'); % vehicleDataset = data.carDataset; % table, containing file path and groundTruth data = load('./data/vehicleDatasetGroundTruth.mat'); vehicleDataset = data.vehicleDataset; % % type table, containing the file path and groundTruth add the absolute path to vehicleDataset vehicleDataset. ImageFilename = fullfile ([PWD,'/data/'],vehicleDataset.imageFilename); % displays an image in the dataset to understand the type of image it contains. vehicleDataset(1:4The data set is divided into two parts: one is the training set for training the detector and the other is the test set for evaluating the detector. % to choose70% of data for training and the rest for evaluation. rng(0); % control of random number generation shuffledIndices = randperm(height(vehicleDataset)); idx =floor(0.7 * length(shuffledIndices) );
trainingDataTbl = vehicleDataset(shuffledIndices(1:idx),:);
testDataTbl = vehicleDataset(shuffledIndices(idx+1:end),:); % Save data and labels imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'}); % path bldsTrain = boxLabelDatastore(trainingDataTbl(:,'vehicle')); ImdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,'vehicle')); TrainingData = combine(imdsTrain,bldsTrain); % combine file path and real box testData = combine(imdsTest,bldsTest); % data = read(trainingData); % data includes picture data, real box coordinates, category I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox); % annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)% Display image % Create YOLO network inputSize= [224 224 3];
numClasses = width(vehicleDataset)- 1; % % category number by column number of the table calculation used to assess the anchor box number trainingDataForEstimation = transform (trainingData, @ (data) preprocessData (data, inputSize)); numAnchors =7; [anchorBoxes, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation, NumAnchors) % feature extraction layer adopts resnet50 featureExtractionNetwork = resnet50; featureLayer ='activation_40_relu'; % set yolo network lgraph = yolov2Layers (inputSize numClasses, anchorBoxes, featureExtractionNetwork, featureLayer); AugmentedTrainingData = transform(trainingData,@augmentData); % augmentedData = cell(4.1);
for k = 1:4
    data = read(augmentedTrainingData);
    augmentedData{k} = insertShape(data{1},'Rectangle',data{2});
    reset(augmentedTrainingData);
end
figure
montage(augmentedData,'BorderSize'.10)% preprocessing enhanced data preprocessedTrainingData= transform(augmentedTrainingData,@(data)preprocessData(data,inputSize)); data = read(preprocessedTrainingData); % I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)% Training parameter options= trainingOptions('sgdm'.'MiniBatchSize'.16.'InitialLearnRate'.1e-3.'MaxEpochs'.20.'CheckpointPath', tempdir, ...
        'Shuffle'.'never');
    
ifDoTraining % [the detector, the info] = trainYOLOv2ObjectDetector training YOLOv2 detector (preprocessedTrainingData lgraph, options);elsePretrained = load('yolov2_mytrain.mat'); detector = pretrained.detector; End % test the trained model and display I = imread (testDataTbl. ImageFilename {4});
I = imresize(I,inputSize(1:2));
[bboxes,scores] = detect(detector,I);
 
I = insertObjectAnnotation(I,'rectangle',bboxes,scores);
figure
imshow(I)% Preprocess test set preprocessedTestData= transform(testData,@(data)preprocessData(data,inputSize)); % detectionResults = detect(Detector, preprocessedTestData); % / ap, recall and precision evaluation accuracy = evaluateDetectionPrecision (detectionResults preprocessedTestData);figure
plot(recall,precision)
xlabel('Recall')
ylabel('Precision')
grid on
title(sprintf('Average Precision = %.2f',ap))
 
 
 
Copy the code

3. Operation results



Fourth, note

Version: 2014 a