自定义数据集训练po​intpillars​时并行池关闭

我想请教一下为什么我在matlab上训练pointpillars的时候会出现时不时的并行池idletimeout,并关闭并行池,我的代码如下
% 加载自定义数据集
outputFolder = fullfile(pwd);
path = fullfile(outputFolder,'pcd_files');
lidarData = fileDatastore(path,'ReadFcn',@(x) pcread(x));
% 加载汽车和卡车对象的3-D边界框标签
gtPath = fullfile(outputFolder,'CustomGTruth.mat');
data = load(gtPath,'gTruth');
Labels = timetable2table(data.gTruth.LabelData);
boxLabels = Labels(:,2);
% 显示全景点云
figure
ptCld = preview(lidarData);
ax = pcshow(ptCld.Location);
set(ax,'XLim',[-50 50],'YLim',[-40 40]);
zoom(ax,2.5);
axis off;
% 预处理数据 将全景点云裁剪为前视点云
xMin = 0.0; % X轴的最小值。
yMin = -39.68; % Y轴的最小值。
zMin = -5.0; % Z轴的最小值。
xMax = 69.12; % X轴的最大值。
yMax = 39.68; % Y轴的最大值。
zMax = 5.0; % Z轴的最大值。
xStep = 0.16; % X轴的分辨率。
yStep = 0.16; % Y轴的分辨率。
% 定义点云参数。
pointCloudRange = [xMin xMax yMin yMax zMin zMax];
voxelSize = [xStep yStep];
% 从前视图裁剪输入的全景点云。选择由gridParams指定的感兴趣区域(ROI)内的边界框标签
[croppedPointCloudObj,processedLabels] = cropFrontViewFromLidarData(...
lidarData,boxLabels,pointCloudRange);
% 显示裁剪后的点云和真实边界框标签
pc = croppedPointCloudObj{1,1};
bboxes = [processedLabels.Bicycle{1}];
ax = pcshow(pc);
showShape('cuboid',bboxes,'Parent',ax,'Opacity',0.1,...
'Color','green','LineWidth',0.5);
reset(lidarData);
% 创建数据存储对象
rng(1);
shuffledIndices = randperm(size(processedLabels,1));
idx = floor(0.7 * length(shuffledIndices));
trainData = croppedPointCloudObj(shuffledIndices(1:idx),:);
testData = croppedPointCloudObj(shuffledIndices(idx+1:end),:);
trainLabels = processedLabels(shuffledIndices(1:idx),:);
testLabels = processedLabels(shuffledIndices(idx+1:end),:);
% 为了能够轻松访问数据存储,使用随本示例提供的辅助函数saveptCldToPCD将训练数据保存为PCD文件。如果您的训练数据已保存在文件夹中并受pcread函数支持,则可以将writeFiles设置为"false"
writeFiles = true;
dataLocation = fullfile(outputFolder,'InputData');
[trainData,trainLabels] = saveptCldToPCD(trainData,trainLabels,...
dataLocation,writeFiles);
% 使用fileDatastore创建文件数据存储
lds = fileDatastore(dataLocation,'ReadFcn',@(x) pcread(x));
% 使用boxLabelDatastore创建边界框标签数据存储
bds = boxLabelDatastore(trainLabels);
% 使用 combine 函数将点云和 3-D 边界框标签合并到一个单一的数据存储中以用于训练
cds = combine(lds,bds);
% % 执行数据增强
augData = preview(cds);
[ptCld,bboxes,labels] = deal(augData{1},augData{2},augData{3});
% 定义物体检测的类别。
classNames = {'Bicycle'};
% 定义每个类别的颜色以绘制边界框。
colors = {'green'};
helperShowPointCloudWith3DBoxes(ptCld,bboxes,labels,classNames,colors)
% % 使用 sampleLidarData 函数从训练数据中采样 3-D 边界框及其对应点
sampleLocation = fullfile(outputFolder,'GTsamples');
[ldsSampled,bdsSampled] = sampleLidarData(cds,classNames,'MinPoints',20,...
'Verbose',false,'WriteLocation',sampleLocation);
cdsSampled = combine(ldsSampled,bdsSampled);
% % 使用 pcBboxOversample 函数随机向每个点云添加固定数量的汽车和卡车类对象。使用 transform 函数将真实数据和自定义数据增强应用于训练数据
numObjects = [5];
cdsAugmented = transform(cds,@(x)pcBboxOversample(x,cdsSampled,classNames,numObjects));
% helperAugmentLidarData 对每个点云应用以下额外的数据增强技术
cdsAugmented = transform(cdsAugmented,@(x)helperAugmentData(x));
% % 显示增强后的点云以及真实增强后的边界框
augData = preview(cdsAugmented);
[ptCld,bboxes,labels] = deal(augData{1},augData{2},augData{3});
helperShowPointCloudWith3DBoxes(ptCld,bboxes,labels,classNames,colors)
% % 从训练数据中估计锚框
anchorBoxes = calculateAnchorsPointPillars(trainLabels);
% 定义 PointPillars 检测器
detector = pointPillarsObjectDetector(pointCloudRange,classNames,anchorBoxes,...
'VoxelSize',voxelSize);
% 指定训练选项
executionEnvironment = "auto";
options = trainingOptions('adam',...
Plots = "training-progress",...
MaxEpochs = 50,...
MiniBatchSize = 6,...
GradientDecayFactor = 0.9,...
SquaredGradientDecayFactor = 0.999,...
LearnRateSchedule = "piecewise",...
InitialLearnRate = 0.0002,...
LearnRateDropPeriod = 15,...
LearnRateDropFactor = 0.8,...
ExecutionEnvironment= executionEnvironment, ...
PreprocessingEnvironment = 'parallel',...
BatchNormalizationStatistics = 'moving',...
ResetInputNormalization = false,...
CheckpointFrequency = 10, ...
CheckpointFrequencyUnit = 'epoch', ...
CheckpointPath = userpath);
% % 训练 PointPillars 目标检测器 或 加载预训练的检测器
doTraining = true;
if doTraining
[detector,info] = trainPointPillarsObjectDetector(cdsAugmented,detector,options);
else
pretrainedDetector = load('net_checkpoint__273__2026_03_12__22_14_30.mat','net');
detector = pretrainedDetector.net;
end
% % 生成检测结果
ptCloud = testData{10,1};
% 在测试点云上运行检测器。
[bboxes,score,labels] = detect(detector,ptCloud,'Threshold',0.5);
% 在点云上显示预测结果。
helperShowPointCloudWith3DBoxes(ptCloud,bboxes,labels,classNames,colors)
% % 使用测试集评估检测器
numInputs = size(testData, 1);
% 从立方体标签生成旋转矩形。
bds = boxLabelDatastore(testLabels(1:numInputs,:));
groundTruthData = transform(bds,@(x)createRotRect(x));
detectionResults = detect(detector,testData(1:numInputs,:),...
'Threshold',0.5);
% 将边界框转换为旋转矩形格式并计算评估指标。
for i = 1:height(detectionResults)
box = detectionResults.Boxes{i};
detectionResults.Boxes{i} = box(:,[1,2,4,5,9]);
detectionResults.Labels{i} = reshape(detectionResults.Labels{i}, [], 1);
end
% 使用平均方向相似性度量评估目标检测器。
metrics = evaluateObjectDetection(detectionResults,groundTruthData,"AdditionalMetrics","AOS");
[datasetSummary,classSummary] = summarize(metrics)
% % helperShowPointCloudWith3DBoxes 函数显示点云及其关联的边界框,使用不同颜色区分不同类别以方便区分。
function helperShowPointCloudWith3DBoxes(ptCld,bboxes,labels,classNames,colors)
% 验证 classNames 和 colors 的长度是否相同
assert(numel(classNames) == numel(colors), 'ClassNames 和 Colors 必须具有相同数量的元素.');
% 从标签中获取唯一类别
uniqueCategories = categories(labels);
% 创建类别到颜色的映射
colorMap = containers.Map(uniqueCategories, colors);
labelColor = cell(size(labels));
% 根据映射填充 labelColor
for i = 1:length(labels)
labelColor{i} = colorMap(char(labels(i)));
end
figure;
ax = pcshow(ptCld);
showShape('cuboid', bboxes, 'Parent', ax, 'Opacity', 0.1, ...
'Color', labelColor, 'LineWidth', 0.5);
zoom(ax,1.5);
end
% % helperAugmentData 函数对数据应用以下增强
function data = helperAugmentData(data)
% 应用随机缩放、旋转和平移。
pc = data{1};
minAngle = -45;
maxAngle = 45;
% 根据网格大小和 XYZ 限制定义输出视图。
outView = imref3d([32,32,32],[-100,100],...
[-100,100],[-100,100]);
theta = minAngle + rand(1,1)*(maxAngle - minAngle);
tform = randomAffine3d('Rotation',@() deal([0,0,1],theta),...
'Scale',[0.95,1.05],...
'XTranslation',[0,0.2],...
'YTranslation',[0,0.2],...
'ZTranslation',[0,0.1]);
% 将变换应用于点云。
ptCloudTransformed = pctransform(pc,tform);
% 将相同的变换应用于边界框。
bbox = data{2};
[bbox,indices] = bboxwarp(bbox,tform,outView);
if ~isempty(indices)
data{1} = ptCloudTransformed;
data{2} = bbox;
data{3} = data{1,3}(indices,:);
end
end

2 Comments

Isha
Isha on 18 Mar 2026
Hello,
With “PreprocessingEnvironment= ‘parallel’ ”, MATLAB spins up a parallel pool for data loading/augmentation. When workers sit idle (e.g., while the GPU trains), the pool hits its IdleTimeout and autoshuts down, interrupting training. This is standard pool behavior.
You can make data reads steadier, by aligning datastore ReadSize to MiniBatchSize, reducing I/O stalls.
Hope this helps.
ZHILONG
ZHILONG on 27 Mar 2026 at 3:48
thanks!! I has temporarily solved this problem through changing parallel pool setting

Sign in to comment.

Answers (0)

Asked:

on 15 Mar 2026

Commented:

on 27 Mar 2026 at 3:48

Community Treasure Hunt

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

Start Hunting!