Create custom people detector for automated labelling on own specific dataset

I have applied the built-in ACFpeopleDetector for automated labelling on my own dataset of people in a rail station (not upright still images) and it is not very accurate. I have also tried to create and train a custom ACFobjectDetector (307 training images for 3075 dataset) but is not an improvement. Is there a way to pre-process (like instance segmentation) a dataset of people in a rail station to make the labelling more accurate? The dataset is people walking through a specific area at an overhead angle and thus the frames are not perfectly still images of people and many times with people behind one another.

Answers (2)

Hi
In order to label the objects, you can use image labeler app with custom algorithm option.The custom algorithm can be YOLOv3/ FasterRCNN/ any deep learning network pretrained on COCO dataset. For more information on custom algorithm approach, you can refer to this documentation and this example. Try to use YOLO3,it may work in your case.
Hope it will help!
I am having trouble actually importing those various detectors into ImageLabeler. I have tried to run the matlab examples for creating a rcnnmask but the examples gives errors such as "unrecognized variable or function segmentObjects" and tried loading a pretrained RCNN gives "variable 'net' orginally saved as maskrcnn cannot be instantiated as an object and will be read as an unint32".
Could you possibly assist? Where can I find the necessary files to import those detectors in ImageLabeler? (since can't be .mat files and should be .m I assume)

3 Comments

Hi
You can use a custom algorithm option while doing labeling, for example you can use YOLOv3 in your case as follows:
  1. Save the below code in your current working directory,
  2. Select this file as automation algorithm in image/video labeler
  3. Click on automate button, it will create prediction as per YOLOv3 (you can use any other algorithm in place of that).
  4. Adjust the prediction if they are not proper.
  5. Save/ export the labels as gTruth object.
classdef MyCustomAlgorithmForLabeling < vision.labeler.AutomationAlgorithm & vision.labeler.mixin.Temporal
properties(Constant)
% Name: Give a name for your algorithm.
Name = 'Example YOLOv3 Algorithm';
% Description: Provide a one-line description for your algorithm.
Description = 'This is an example of a custom automation algorithm.';
UserDirections = {...
vision.labeler.AutomationAlgorithm.getDefaultUserDirections('selectroidef', vision.getMessage('vision:labeler:People')),...
vision.labeler.AutomationAlgorithm.getDefaultUserDirections('rundetector', vision.getMessage('vision:labeler:People')),...
vision.labeler.AutomationAlgorithm.getDefaultUserDirections('review'),...
vision.labeler.AutomationAlgorithm.getDefaultUserDirections('rerun'),...
vision.labeler.AutomationAlgorithm.getDefaultUserDirections('accept')...
};
end
properties
%------------------------------------------------------------------
% Place your code here
%------------------------------------------------------------------
detector
SelectedLabelName
end
methods
function isValid = checkLabelDefinition(~, labelDef)
%--------------------------------------------------------------
% Place your code here
isValid = (labelDef.Type == labelType.Rectangle);
%--------------------------------------------------------------
end
end
methods
function initialize(algObj, I, labelsToAutomate)
% disp(['Executing initialize on the first image frame at ' char(seconds(algObj.CurrentTime))])
%--------------------------------------------------------------
% Place your code here
%--------------------------------------------------------------
algObj.detector = yolov3ObjectDetector('darknet53-coco');
end
%
function autoLabels = run(algObj, I)
autoLabels = [];
%--------------------------------------------------------------
% Place your code here
%--------------------------------------------------------------
I = im2double(I);
[bboxes, scores, labels] = detect(algObj.detector,I);
idx = labels=='person';
personBox = bboxes(idx,:);
% personScores{i,1} = scores(idx);
personLabel = labels(idx);
if(~isempty(personLabel))
autoLabels.Name = algObj.SelectedLabelDefinitions.Name;
autoLabels.Position = personBox;
autoLabels.Type = labelType.Rectangle;
end
end
function terminate(algObj)
disp('Executing terminate')
end
end
end
Hope it will help!
Hi. Thank you for the code. I have saved it as a .m file and tried to import it into the algorithm selection in ImageLabeler but get an error "MyCustomAlgorithmForLabeling is not an automation algorithm". I am currently using Matlab 2021b and have all the necessary toolboxes downloaded so I am not sure why I am not even able to run Matlab examples sucessfully.

Sign in to comment.

Asked:

on 1 Oct 2021

Commented:

on 8 Oct 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!