Is it possible to use a pretrained YOLO DL NW to train new data without changing its layers?
Mostra commenti meno recenti
Hi all,
I was following the example from https://www.mathworks.com/help/vision/ref/trainyolov4objectdetector.html#mw_c9123667-38e8-4d10-959c-35af840d92d0 that teaches how to use a pretrained YOLOv4 DL NW to train it for detection of new objects.
Following the instructions from MATLAB documentation, I currently have the below code, that basically changes the dataset used to train the pretrained loaded YOLOv4 NW.
My goal is to train a DL network to detect LED matrices automatically. So, what I would like to know is: It is ok to use the pretrained NW to detect new objects from my own dataset ?
If yes, should I change a specific layer or training option?
Regards.
detector = yolov4ObjectDetector("tiny-yolov4-coco");
data = load("LEDMatrixData.mat");
trainingData = data.LEDMatrixData;
imds = imageDatastore('C:\Users\Fortu\OneDrive\Área de Trabalho\OCC\OCC_codes\Movie Frames from AMOSTRAS_4_ARDUINO_P4_CL_BRILHO_0');
blds = boxLabelDatastore(trainingData(:,2:end));
ds = combine(imds,blds);
inputSize = [224 224 3];
trainingDataForEstimation = transform(ds,@(data)preprocessData(data,inputSize));
numAnchors = 4;
[anchors, meanIoU] = estimateAnchorBoxes(trainingDataForEstimation,numAnchors);
area = anchors(:,1).*anchors(:,2);
[~,idx] = sort(area,"descend");
anchors = anchors(idx,:);
anchorBoxes = {anchors(1:3,:);anchors(4:6,:)};
classes = {'LEDMatrix'};
detector = yolov4ObjectDetector("tiny-yolov4-coco",classes,anchorBoxes,InputSize=inputSize);
options = trainingOptions("sgdm", ...
InitialLearnRate=0.001, ...
MiniBatchSize=16,...
MaxEpochs=40, ...
BatchNormalizationStatistics="moving",...
ResetInputNormalization=false,...
VerboseFrequency=30);
trainedDetector = trainYOLOv4ObjectDetector(ds,detector,options)
%-------------------------------------------------------------------------------------------------%
function data = preprocessData(data,targetSize)
for num = 1:size(data,1)
I = data{num,1};
imgSize = size(I);
bboxes = data{num,2};
I = im2single(imresize(I,targetSize(1:2)));
scale = targetSize(1:2)./imgSize(1:2);
bboxes = bboxresize(bboxes,scale);
data(num,1:2) = {I,bboxes};
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!