✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
车辆目标检测是自动驾驶中的一个重要环节.针对复杂场景下的车辆目标检测模型检测速度慢,检测精度和召回率低等问题,以YOLO网络为基础,加载预训练模型,多尺寸图像训练,最终得到车辆目标检测模型.实验表明,本文方法可以在保证检测速度的情况下,尽可能多地检测出更多车辆目标且精度较高.
⛄ 部分代码
clc; clear all; close all;
rng(0);
checkpoint_folder = fullfile(pwd, 'checkpoint_folder_car');
data = load(fullfile(pwd, 'vehicleDatasetGroundTruth.mat'));
vehicleDataset = data.vehicleDataset;
vehicleDataset(1:4,:)
vehicleDataset.imageFilename = fullfile(pwd, vehicleDataset.imageFilename);
im_list = [];
for i = 1 : 4
I = imread(vehicleDataset.imageFilename{i});
I = insertShape(I,'Rectangle',vehicleDataset.vehicle{i});
im_list(:,:,:,i) = mat2gray(I);
end
figure; montage(im_list);
shuffled_index = randperm(size(vehicleDataset,1));
idx = floor(0.8 * length(shuffled_index));
train_data = vehicleDataset(shuffled_index(1:idx),:);
test_data = vehicleDataset(shuffled_index(idx+1:end),:);
image_size = [224 224 3];
num_classes = size(vehicleDataset,2)-1;
anchor_boxes = [
43 59
18 22
23 29
84 109
];
base_network = resnet50;
featureLayer = 'activation_40_relu';
lgraph = yolov2Layers(image_size,num_classes,anchor_boxes,base_network,featureLayer);
options = trainingOptions('sgdm', ...
'MiniBatchSize', 16, ....
'InitialLearnRate',1e-3, ...
'MaxEpochs',100,...
'CheckpointPath', checkpoint_folder, ...
'Shuffle','every-epoch', ...
'ExecutionEnvironment', 'gpu');
[detector,info] = trainYOLOv2ObjectDetector(train_data,lgraph,options);
I = imread(test_data.imageFilename{1});
[bboxes,scores] = detect(detector,I);
I = insertObjectAnnotation(I,'rectangle',bboxes,scores);
figure; imshow(I); title('测试样例');
num_test_images = size(test_data,1);
results = table('Size',[num_test_images 3],...
'VariableTypes',{'cell','cell','cell'},...
'VariableNames',{'Boxes','Scores','Labels'});
for i = 1:num_test_images
I = imread(test_data.imageFilename{i});
[bboxes,scores,labels] = detect(detector,I);
results.Boxes{i} = bboxes;
results.Scores{i} = scores;
results.Labels{i} = labels;
end
expected_results = test_data(:, 2:end);
[ap, recall, precision] = evaluateDetectionPrecision(results, expected_results);
plot(recall,precision)
xlabel('召回率')
ylabel('准确率')
grid on
title(sprintf('平均准确率 = %.2f', ap))
⛄ 运行结果
⛄ 参考文献
[1] 殷远齐, 徐源, 邢远新. 基于YOLO v4的车辆目标检测算法[J]. 计算机与现代化, 2022(000-007).
[2] 向昌成, 黄成兵, 罗平,等. 基于YOLO算法的无人机航拍图像车辆目标检测系统研究[J]. 计算机与数字工程, 2021.
[3] 龚庆武, 乔卉, 刘栋,等. 基于YOLO算法的电能质量扰动检测方法:, CN201910881278.7[P]. 2022.
[4] 李云鹏, 侯凌燕, 王超. 基于YOLOv2的复杂场景下车辆目标检测[J]. 电视技术, 2018, 42(5):7.