PointPillars 深層学習を使用した LiDAR オブジェクト検出用のコード生成
R2026bこの例では、PointPillars オブジェクト検出器用に CUDA® MEX を生成する方法を説明します。詳細については、Lidar Toolbox™ のPointPillars 深層学習を使用した LiDAR の 3 次元オブジェクト検出の例を参照してください。
サードパーティの前提条件
必須
CUDA 対応 NVIDIA® GPU および互換性のあるドライバー。
オプション
スタティック ライブラリ、ダイナミック ライブラリ、実行可能ファイルなどの MEX 以外のビルドについて、この例には次の追加要件があります。
NVIDIA CUDA ツールキット。
NVIDIA cuDNN ライブラリ。
コンパイラおよびライブラリの環境変数。詳細については、サードパーティ ハードウェア (GPU Coder)と前提条件となる製品の設定 (GPU Coder)を参照してください。
GPU 環境の検証
この例を実行するためのコンパイラおよびライブラリが正しく設定されていることを確認するために、関数coder.checkGpuInstall (GPU Coder)を使用します。
envCfg = coder.gpuEnvConfig("host"); envCfg.DeepLibTarget = "cudnn"; envCfg.DeepCodegen = 1; envCfg.Quiet = 1; coder.checkGpuInstall(envCfg);
事前学習済みの PointPillars ネットワーク
PointPillars 深層学習を使用した LiDAR の 3 次元オブジェクト検出の例で学習させた、事前学習済みのpointPillarsObjectDetectorを読み込みます。自分で検出器に学習させるには、PointPillars 深層学習を使用した LiDAR の 3 次元オブジェクト検出を参照してください。
matFile = "pretrainedPointPillarsDetector.mat"; pretrainedDetector = load("pretrainedPointPillarsDetector.mat","detector"); detector = pretrainedDetector.detector;
エントリポイント関数 pointpillarsDetect
pointpillarsDetect エントリポイント関数は、点群と信頼しきい値を入力として受け取り、それらを pointpillarDetect 関数を介して予測用の学習済みpointPillarsObjectDetectorに渡します。関数 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 (GPU Coder)を使用して 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. Accessed September 18, 2025. https://pandaset.org/. The PandaSet data set is provided under the CC-BY-4.0 license.
[3] Xiao, Pengchuan, Zhenlei Shao, Steven Hao, et al. “PandaSet: Advanced Sensor Suite Dataset for Autonomous Driving.” 2021 IEEE International Intelligent Transportation Systems Conference (ITSC), IEEE, September 19, 2021, 3095–101. https://doi.org/10.1109/ITSC48978.2021.9565009.