Automatic Driving Scene Image Segmentation (Unet)

This paper uses the matlab environment to test the image segmentation task of the autonomous driving scene. Split the network using Unet.

One thousand labeled images, and the final training accuracy reaches 90%.

 

 data preparation

Scene pre-label data download address: Semantic Segmentation for Self Driving Cars | Kaggle

Data download may need to overturn the wall, if you can't download it, you can move the automatic driving scene image-segmented and labeled data.zip

The data is marked with 13 categories, and the specific name of each category is unknown. Just give a class name to test.

imagedir="E:\DLDatasets\kaggle\SelfDriving\dataA\dataA\CameraRGB";
labeldir="E:\DLDatasets\kaggle\SelfDriving\dataA\dataA\CameraSeg";

classNames=["c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12"];
labelIds=0:12;

imds=imageDatastore(imagedir, "ReadFcn",@readImage);
pxds=pixelLabelDatastore(labeldir,classNames,labelIds,"ReadFcn",@readLabel);

ds=combine(imds,pxds);

The original size of the image is 600x800. First, the custom data read function scales it to 96x128. In addition, the marked image is three-channel and needs to be converted into a single-channel image.

function [data] = readImage(path)
    data=imread(path);
    data=imresize(data,[96 128]);
end

function [data] = readLabel(path)
    data=imread(path);
    data=data(:,:,1);
    data=imresize(data,[96 128]);
end

Define network and parameters

% 定义网络
imageSize = [96 128 3];
numClasses = 13;
lgraph = unetLayers(imageSize, numClasses);
% 训练参数
options = trainingOptions('adam', ...
    'InitialLearnRate',1e-3, ...   % 1e-4不收敛,改为1e-3
    'MaxEpochs',100, ...
    "MiniBatchSize", 8,...
    'VerboseFrequency',50, ...
    'Plots','training-progress');

 train

net = trainNetwork(ds,lgraph,options)

final training situation

 test

pic = imread("E:\DLDatasets\kaggle\SelfDriving\dataA\dataA\CameraRgb\02_00_120.png");
msk = imread("E:\DLDatasets\kaggle\SelfDriving\dataA\dataA\CameraSeg\02_00_120.png");
pic = imresize(pic, [96,128]);
msk = imresize(msk, [96,128]);
msk=msk(:,:,1);
out2 = predict(net,pic);

[h,w,~] = size(out2);
result = uint8(zeros(h,w));

for y = 1:h
    for x = 1:w
        [~,i]=max(out2(y,x,:));
        result(y,x)=i-1;
    end
end

result = result*20;

msk = msk*20;

subplot(1,3,1)
imshow(pic)
subplot(1,3,2)
imshow(result,'Colormap',jet(255))
subplot(1,3,3)
imshow(msk,'Colormap',jet(255))

 

 

 

Guess you like

Origin blog.csdn.net/Ango_/article/details/121751666