Main Content

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

深層学習用の点群データのインポート

深層学習ワークフローで点群データを使用する場合、そのデータはデータセットから未処理の形式で MATLAB に読み取らなければなりません。この例では、Sydney Urban Objects Dataset [1] を使用します。この例では、MATLAB のデータストアを使用して、深層学習用データの読み取りと表示を行う方法を説明します。

Sydney Urban Objects Dataset のダウンロード

Sydney Urban Objects のデータは非圧縮形式で 122 MB あり、お使いのネットワークの接続速度によってはダウンロードにしばらく時間がかかることがあります。

sydneyUrbanObjectsPath = downloadSydneyUrbanObjects(tempdir());

点群データ用データストアの定義

データストアを作成して、点群データを Sydney Urban Objects から、関連付けられたオブジェクト ラベルとともに読み込みます。

ds = loadSydneyUrbanObjectsData(sydneyUrbanObjectsPath);

データストアから 1 番目の観測値を読み取り、表示します。

data = preview(ds)
data=1×2 cell array
    {1×1 pointCloud}    {[4wd]}

disp(data)
    {1×1 pointCloud}    {[4wd]}

データストアの読み取りとプレビューのメソッドの出力は cell 配列であり、配列の 1 列目は pointCloud オブジェクト、2 列目は関連付けられたクラス ラベルです。pointCloud オブジェクトは関数 pcshow を使用して視覚化できます。

figure
pcshow(data{1})
title(string(data{2}))

参考文献

[1] Alastair Quadros, James Underwood, Bertrand Douillard; 2013. Sydney Urban Objects Dataset.

サポート関数

function datasetPath = downloadSydneyUrbanObjects(dataLoc)
% This function downloads the Sydney Urban Objects tar archive to tempdir
% provides as output the location of where the data was saved.

if nargin == 0
    dataLoc = pwd();
end

dataLoc = string(dataLoc);

url = "http://www.acfr.usyd.edu.au/papers/data/";
name = "sydney-urban-objects-dataset.tar.gz";

if ~exist(fullfile(dataLoc,'sydney-urban-objects-dataset'),'dir')
    disp('Downloading Sydney Urban Objects Dataset...');
    untar(url+name,dataLoc);
end

datasetPath = dataLoc.append('sydney-urban-objects-dataset');

end

function ds = loadSydneyUrbanObjectsData(datapath,folds)
% loadSydneyUrbanObjectsData Create datastore with point clouds and
% associated categorical labels for Sydney Urban Objects dataset.
%
% ds = loadSydneyUrbanObjectsData(datapath) returns a datastore that
% represents point clouds and associated categories for the Sydney Urban
% Objects dataset. The input, datapath, is a string or char array which
% represents the path to the root directory of the Sydney Urban Objects
% Dataset.
%
% ds = loadSydneyUrbanObjectsData(___,folds) optionally allows
% specification of desired folds that you wish to be included in the
% output ds. For example, [1 2 4] specifies that you want the first,
% second, and fourth folds of the Dataset. Default: [1 2 3 4].

if nargin < 2
    folds = 1:4;
end

datapath = string(datapath);
path = fullfile(datapath,'objects',filesep);

% For now, include all folds in Datastore
foldNames{1} = importdata(fullfile(datapath,'folds','fold0.txt'));
foldNames{2} = importdata(fullfile(datapath,'folds','fold1.txt'));
foldNames{3} = importdata(fullfile(datapath,'folds','fold2.txt'));
foldNames{4} = importdata(fullfile(datapath,'folds','fold3.txt'));
names = foldNames(folds);
names = vertcat(names{:});

fullFilenames = append(path,names);
ds = fileDatastore(fullFilenames,'ReadFcn',@extractTrainingData,'FileExtensions','.bin');

end

function dataOut = extractTrainingData(fname)

[pointData,intensity] = readbin(fname);

[~,name] = fileparts(fname);
name = string(name);
name = extractBefore(name,'.');

labelNames = ["4wd","bench","bicycle","biker",...
    "building","bus","car","cyclist","excavator","pedestrian","pillar",...
    "pole","post","scooter","ticket_machine","traffic_lights","traffic_sign",...
    "trailer","trash","tree","truck","trunk","umbrella","ute","van","vegetation"];

label = categorical(name,labelNames);

dataOut = {pointCloud(pointData,'Intensity',intensity),label};

end

function [pointData,intensity] = readbin(fname)
% readbin Read point and intensity data from Sydney Urban Object binary
% files.

% names = ['t','intensity','id',...
%          'x','y','z',...
%          'azimuth','range','pid']
% 
% formats = ['int64', 'uint8', 'uint8',...
%            'float32', 'float32', 'float32',...
%            'float32', 'float32', 'int32']

fid = fopen(fname, 'r');
c = onCleanup(@() fclose(fid));
    
fseek(fid,10,-1); % Move to the first X point location 10 bytes from beginning
X = fread(fid,inf,'single',30);
fseek(fid,14,-1);
Y = fread(fid,inf,'single',30);
fseek(fid,18,-1);
Z = fread(fid,inf,'single',30);

fseek(fid,8,-1);
intensity = fread(fid,inf,'uint8',33);

pointData = [X,Y,Z];

end