Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

PointPillars 深層学習を使用した LiDAR オブジェクト検出用のコード生成

この例では、PointPillars オブジェクト検出器用の CUDA® MEX を生成する方法を示します。詳細については、Lidar Toolbox™ のPointPillars 深層学習を使用した LiDAR の 3 次元オブジェクト検出 (Lidar Toolbox)の例を参照してください。

サードパーティの必要条件

必須

  • CUDA 対応 NVIDIA® GPU および互換性のあるドライバー。

オプション

スタティック ライブラリ、ダイナミック ライブラリ、または実行可能ファイルなどの MEX 以外のビルドについて、この例では以下の要件も適用されます。

GPU 環境の検証

この例を実行するためのコンパイラおよびライブラリが正しく設定されていることを確認するために、関数coder.checkGpuInstallを使用します。

envCfg = coder.gpuEnvConfig('host');
envCfg.DeepLibTarget = 'cudnn';
envCfg.DeepCodegen = 1;
envCfg.Quiet = 1;
coder.checkGpuInstall(envCfg);

事前学習済みの PointPillars ネットワーク

"PointPillars 深層学習を使用した 3 次元 LIDAR オブジェクト検出の例" で学習させた事前学習済みのpointPillarsObjectDetector (Lidar Toolbox)を読み込みます。自分で検出器に学習させるには、PointPillars 深層学習を使用した LiDAR の 3 次元オブジェクト検出 (Lidar Toolbox)を参照してください。

matFile = 'pretrainedPointPillarsDetector.mat';
pretrainedDetector = load('pretrainedPointPillarsDetector.mat','detector');
detector = pretrainedDetector.detector;

エントリポイント関数 pointpillarsDetect

エントリポイント関数 pointpillarsDetect は、点群と信頼しきい値を入力として受け取り、それらを関数 pointpillarDetect を介して予測用の学習済みpointPillarsObjectDetector (Lidar Toolbox)に渡します。関数 pointpillarsDetect は、ネットワーク オブジェクトを MAT ファイルから永続変数に読み込み、後続の予測呼び出しでその永続オブジェクトを再利用します。

type('pointpillarsDetect.m')
function [bboxes,scores,labels] = pointpillarsDetect(matFile,dataLoc,dataInt,threshold)
% Predict the output of network and extract the confidence, x, y,
% width, height, and class.

% load the deep learning network for prediction
persistent pointPillarObj;

if isempty(pointPillarObj)
    pointPillarObj = coder.loadDeepLearningNetwork(matFile);
end

ptCloud = pointCloud(dataLoc,'Intensity',dataInt);

[bboxes,scores,labels] = pointPillarObj.detect(ptCloud,'Threshold',threshold);
end

オブジェクト検出用の検出器の評価

点群を読み取ります。

pc = pcread('pandasetDrivingData.pcd');

事前学習済みの検出器で検出メソッドを使用します。

confidenceThreshold = 0.7;
[bboxes,~,labels] = detect(detector,pc,'Threshold',confidenceThreshold);
bboxesCar = bboxes(labels == 'Car',:);
bboxesTruck = bboxes(labels == 'Truck',:);

検出結果を点群に表示します。

helperDisplay3DBoxesOverlaidPointCloud(pc.Location,bboxesCar,'green',...
                      bboxesTruck,'magenta','Predicted bounding boxes');

CUDA MEX の生成

エントリポイント関数 pointpillarsDetect 用の CUDA® コードを生成するには、MEX ターゲットの GPU コード構成オブジェクトを作成し、ターゲット言語を C++ に設定します。関数coder.DeepLearningConfigを使用して cuDNN 深層学習構成オブジェクトを作成し、それを GPU コード構成オブジェクトの DeepLearningConfig プロパティに割り当てます。

cfg = coder.gpuConfig('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig(TargetLibrary='cudnn');

dataLoc = pc.Location;
dataInt = pc.Intensity;

args = {coder.Constant(matFile) coder.typeof(dataLoc,[Inf,3],[1 0]) coder.typeof(dataInt,[Inf,1],[1 0]) coder.typeof(confidenceThreshold)};

codegen -config cfg pointpillarsDetect -args args -report
Code generation successful: View report

生成された MEX の実行

生成された CUDA MEX を点群で呼び出します。結果を表示します。

[bboxes,~,labels] = pointpillarsDetect_mex(matFile,dataLoc,dataInt,confidenceThreshold);
bboxesCar = bboxes(labels == 'Car',:);
bboxesTruck = bboxes(labels == 'Truck',:);

helperDisplay3DBoxesOverlaidPointCloud(pc.Location,bboxesCar,'green',...
                      bboxesTruck,'magenta','Predicted bounding boxes');

補助関数

function helperDisplay3DBoxesOverlaidPointCloud(ptCld,labelsCar,carColor,...
    labelsTruck,truckColor,titleForFigure)
% Display the point cloud with different colored bounding boxes for different
% classes
    figure;
    ax = pcshow(ptCld);
    showShape('cuboid',labelsCar,'Parent',ax,'Opacity',0.1,'Color',...
        carColor,'LineWidth',0.5);
    hold on;
    showShape('cuboid',labelsTruck,'Parent',ax,'Opacity',0.1,'Color',...
        truckColor,'LineWidth',0.5);
    title(titleForFigure);
    zoom(ax,1.5);
end

参考文献

[1] Lang, Alex H., Sourabh Vora, Holger Caesar, Lubing Zhou, Jiong Yang, and Oscar Beijbom. "PointPillars: Fast Encoders for Object Detection From Point Clouds." In 2019 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 12689-12697. Long Beach, CA, USA: IEEE, 2019. https://doi.org/10.1109/CVPR.2019.01298.

[2] Hesai and Scale.PandaSet. https://scale.com/open-datasets/pandaset.