このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
objectDetectorTrainingData
オブジェクト検出器用の学習データの作成
構文
説明
[
は、指定されたグラウンド トゥルースからイメージ データストアとボックス ラベル データストアの学習データを作成します。この関数は、1 つ以上の注釈付きオブジェクトを含むイメージのみをグラウンド トゥルース入力から選択します。imds
,blds
] = objectDetectorTrainingData(gTruth
)
combine
(imds
,blds
) を使用してイメージとボックス ラベルのデータストアを統合し、学習に必要なデータストアを作成することができます。統合されたデータストアは、trainACFObjectDetector
、trainYOLOv2ObjectDetector
、trainYOLOv4ObjectDetector
、trainFastRCNNObjectDetector
、trainFasterRCNNObjectDetector
、および trainRCNNObjectDetector
などの学習関数で使用します。
この関数は、複数の MATLAB® ワーカーを使用する並列計算をサポートします。Computer Vision Toolbox の基本設定 ダイアログを使用して並列計算を有効にします。
は、指定されたグラウンド トゥルースから学習データの table を返します。trainingDataTable
= objectDetectorTrainingData(gTruth
)gTruth
は、groundTruth
オブジェクトの配列です。table は、Computer Vision Toolbox™ の学習関数を使用したオブジェクト検出器の学習に使用できます。
[___] = objectDetectorTrainingData(
は、前の構文にある引数の任意の組み合わせに加えて、名前と値の引数を 1 つ以上使用してオプションを指定します。たとえば、gTruth
,Name=Value
)Verbose=True
は、ワークスペース環境への表示を有効にします。
gTruth
の groundTruth
オブジェクトを、ビデオ ファイル、カスタム データ ソース、または異なるカスタム読み取り関数を指定した imageDatastore
オブジェクトを使用して作成する場合、任意の組み合わせの名前と値の引数を指定できます。イメージ コレクションまたはイメージ シーケンス データ ソースから groundTruth
オブジェクトを作成した場合は、SamplingFactor
と LabelType
の名前と値の引数のみ指定できます。
例
YOLO v2 車両検出器の学習
YOLO v2 ネットワークに基づいて車両検出器に学習させます。
イメージを含むフォルダーをワークスペースに追加します。
imageDir = fullfile(matlabroot,'toolbox','vision','visiondata','vehicles'); addpath(imageDir);
車両のグラウンド トゥルース データを読み込みます。
data = load('vehicleTrainingGroundTruth.mat');
gTruth = data.vehicleTrainingGroundTruth;
学習用の layerGraph オブジェクトを含む検出器を読み込みます。
vehicleDetector = load('yolov2VehicleDetector.mat');
lgraph = vehicleDetector.lgraph
lgraph = LayerGraph with properties: Layers: [25×1 nnet.cnn.layer.Layer] Connections: [24×2 table] InputNames: {'input'} OutputNames: {'yolov2OutputLayer'}
グラウンド トゥルース オブジェクトを使用して、イメージ データストアとボックス ラベル データストアを作成します。
[imds,bxds] = objectDetectorTrainingData(gTruth);
データストアを統合します。
cds = combine(imds,bxds);
学習オプションを設定します。
options = trainingOptions('sgdm', ... 'InitialLearnRate', 0.001, ... 'Verbose',true, ... 'MiniBatchSize',16, ... 'MaxEpochs',30, ... 'Shuffle','every-epoch', ... 'VerboseFrequency',10);
検出器に学習させます。
[detector,info] = trainYOLOv2ObjectDetector(cds,lgraph,options);
************************************************************************* Training a YOLO v2 Object Detector for the following object classes: * vehicle Training on single CPU. |========================================================================================| | Epoch | Iteration | Time Elapsed | Mini-batch | Mini-batch | Base Learning | | | | (hh:mm:ss) | RMSE | Loss | Rate | |========================================================================================| | 1 | 1 | 00:00:00 | 7.50 | 56.2 | 0.0010 | | 1 | 10 | 00:00:02 | 1.73 | 3.0 | 0.0010 | | 2 | 20 | 00:00:04 | 1.58 | 2.5 | 0.0010 | | 2 | 30 | 00:00:06 | 1.36 | 1.9 | 0.0010 | | 3 | 40 | 00:00:08 | 1.13 | 1.3 | 0.0010 | | 3 | 50 | 00:00:09 | 1.01 | 1.0 | 0.0010 | | 4 | 60 | 00:00:11 | 0.95 | 0.9 | 0.0010 | | 4 | 70 | 00:00:13 | 0.84 | 0.7 | 0.0010 | | 5 | 80 | 00:00:15 | 0.84 | 0.7 | 0.0010 | | 5 | 90 | 00:00:17 | 0.70 | 0.5 | 0.0010 | | 6 | 100 | 00:00:19 | 0.65 | 0.4 | 0.0010 | | 7 | 110 | 00:00:21 | 0.73 | 0.5 | 0.0010 | | 7 | 120 | 00:00:23 | 0.60 | 0.4 | 0.0010 | | 8 | 130 | 00:00:24 | 0.63 | 0.4 | 0.0010 | | 8 | 140 | 00:00:26 | 0.64 | 0.4 | 0.0010 | | 9 | 150 | 00:00:28 | 0.57 | 0.3 | 0.0010 | | 9 | 160 | 00:00:30 | 0.54 | 0.3 | 0.0010 | | 10 | 170 | 00:00:32 | 0.52 | 0.3 | 0.0010 | | 10 | 180 | 00:00:33 | 0.45 | 0.2 | 0.0010 | | 11 | 190 | 00:00:35 | 0.55 | 0.3 | 0.0010 | | 12 | 200 | 00:00:37 | 0.56 | 0.3 | 0.0010 | | 12 | 210 | 00:00:39 | 0.55 | 0.3 | 0.0010 | | 13 | 220 | 00:00:41 | 0.52 | 0.3 | 0.0010 | | 13 | 230 | 00:00:42 | 0.53 | 0.3 | 0.0010 | | 14 | 240 | 00:00:44 | 0.58 | 0.3 | 0.0010 | | 14 | 250 | 00:00:46 | 0.47 | 0.2 | 0.0010 | | 15 | 260 | 00:00:48 | 0.49 | 0.2 | 0.0010 | | 15 | 270 | 00:00:50 | 0.44 | 0.2 | 0.0010 | | 16 | 280 | 00:00:52 | 0.45 | 0.2 | 0.0010 | | 17 | 290 | 00:00:54 | 0.47 | 0.2 | 0.0010 | | 17 | 300 | 00:00:55 | 0.43 | 0.2 | 0.0010 | | 18 | 310 | 00:00:57 | 0.44 | 0.2 | 0.0010 | | 18 | 320 | 00:00:59 | 0.44 | 0.2 | 0.0010 | | 19 | 330 | 00:01:01 | 0.38 | 0.1 | 0.0010 | | 19 | 340 | 00:01:03 | 0.41 | 0.2 | 0.0010 | | 20 | 350 | 00:01:04 | 0.39 | 0.2 | 0.0010 | | 20 | 360 | 00:01:06 | 0.42 | 0.2 | 0.0010 | | 21 | 370 | 00:01:08 | 0.42 | 0.2 | 0.0010 | | 22 | 380 | 00:01:10 | 0.39 | 0.2 | 0.0010 | | 22 | 390 | 00:01:12 | 0.37 | 0.1 | 0.0010 | | 23 | 400 | 00:01:13 | 0.37 | 0.1 | 0.0010 | | 23 | 410 | 00:01:15 | 0.35 | 0.1 | 0.0010 | | 24 | 420 | 00:01:17 | 0.29 | 8.3e-02 | 0.0010 | | 24 | 430 | 00:01:19 | 0.36 | 0.1 | 0.0010 | | 25 | 440 | 00:01:21 | 0.28 | 7.9e-02 | 0.0010 | | 25 | 450 | 00:01:22 | 0.29 | 8.1e-02 | 0.0010 | | 26 | 460 | 00:01:24 | 0.28 | 8.0e-02 | 0.0010 | | 27 | 470 | 00:01:26 | 0.27 | 7.1e-02 | 0.0010 | | 27 | 480 | 00:01:28 | 0.25 | 6.3e-02 | 0.0010 | | 28 | 490 | 00:01:30 | 0.24 | 5.9e-02 | 0.0010 | | 28 | 500 | 00:01:31 | 0.29 | 8.4e-02 | 0.0010 | | 29 | 510 | 00:01:33 | 0.35 | 0.1 | 0.0010 | | 29 | 520 | 00:01:35 | 0.31 | 9.3e-02 | 0.0010 | | 30 | 530 | 00:01:37 | 0.18 | 3.1e-02 | 0.0010 | | 30 | 540 | 00:01:38 | 0.22 | 4.6e-02 | 0.0010 | |========================================================================================| Detector training complete. *************************************************************************
テスト イメージを読み取ります。
I = imread('detectcars.png');
検出器を実行します。
[bboxes,scores] = detect(detector,I);
結果を表示します。
if(~isempty(bboxes)) I = insertObjectAnnotation(I,'rectangle',bboxes,scores); end figure imshow(I)
ACF ベースの一時停止標識検出器の学習
学習データを使用して、ACF ベースの一時停止標識用オブジェクト検出器に学習させます。
MATLAB パスにイメージを含むフォルダーを追加します。
imageDir = fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'stopSignImages'); addpath(imageDir);
グラウンド トゥルース データを読み込みます。これには、一時停止標識と自動車のデータが含まれます。
load('stopSignsAndCarsGroundTruth.mat','stopSignsAndCarsGroundTruth')
ラベル定義を表示して、グラウンド トゥルースに含まれるラベル タイプを確認します。
stopSignsAndCarsGroundTruth.LabelDefinitions
ans=3×3 table
Name Type Group
____________ _________ ________
{'stopSign'} Rectangle {'None'}
{'carRear' } Rectangle {'None'}
{'carFront'} Rectangle {'None'}
学習用の一時停止標識データを選択します。
stopSignGroundTruth = selectLabelsByName(stopSignsAndCarsGroundTruth,'stopSign');
一時停止標識オブジェクト検出器のための学習データを作成します。
trainingData = objectDetectorTrainingData(stopSignGroundTruth); summary(trainingData)
Variables: imageFilename: 41x1 cell array of character vectors stopSign: 41x1 cell
ACF ベースのオブジェクト検出器に学習させます。
acfDetector = trainACFObjectDetector(trainingData,'NegativeSamplesFactor',2);
ACF Object Detector Training The training will take 4 stages. The model size is 34x31. Sample positive examples(~100% Completed) Compute approximation coefficients...Completed. Compute aggregated channel features...Completed. -------------------------------------------- Stage 1: Sample negative examples(~100% Completed) Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 19 weak learners. -------------------------------------------- Stage 2: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 20 weak learners. -------------------------------------------- Stage 3: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 54 weak learners. -------------------------------------------- Stage 4: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 61 weak learners. -------------------------------------------- ACF object detector training is completed. Elapsed time is 14.0736 seconds.
ACF ベースの検出器をサンプル イメージでテストします。
I = imread('stopSignTest.jpg');
bboxes = detect(acfDetector,I);
検出したオブジェクトを表示します。
annotation = acfDetector.ModelName;
I = insertObjectAnnotation(I,'rectangle',bboxes,annotation);
figure
imshow(I)
パスからイメージ フォルダーを削除します。
rmpath(imageDir);
groundTruth からのすべてのラベル属性の読み取り
イメージの場所、ラベル定義、およびラベル データを読み込みます。
data = load('labelsWithAttributes.mat'); images = fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages', data.imageFilenames);
グラウンド トゥルース オブジェクトを作成します。
dataSource = groundTruthDataSource(images); gTruth = groundTruth(groundTruthDataSource(images), data.labeldefs, data.labelData);
グラウンド トゥルース オブジェクトを使用して、イメージ データストア、ボックス ラベル データストア、および配列データストアを作成します。
[imds, blds, arrds] = objectDetectorTrainingData(gTruth);
すべての属性を読み取ります。
readall(arrds)
ans=2×1 cell array
{1x1 struct}
{1x1 struct}
入力引数
gTruth
— グラウンド トゥルース データ
スカラー | groundTruth
オブジェクトの配列
グラウンド トゥルース データ。スカラー、または groundTruth
オブジェクトの配列として指定します。groundTruth
オブジェクトを使用して、既存のグラウンド トゥルース データからグラウンド トゥルース オブジェクトを作成できます。
並列計算を有効にして groundTruth
のカスタム データ ソースを使用すると、リーダー関数は MATLAB ワーカーのプールを使用してデータ ソースからイメージを並列で読み取ると想定されます。
名前と値の引数
オプションの引数のペアを Name1=Value1,...,NameN=ValueN
として指定します。ここで、Name
は引数名で、Value
は対応する値です。名前と値の引数は他の引数の後に指定しなければなりませんが、ペアの順序は重要ではありません。
R2021a より前では、コンマを使用して名前と値をそれぞれ区切り、Name
を引用符で囲みます。
例: (SamplingFactor
=5
) は、サブサンプリング係数を 5
に設定します。
SamplingFactor
— イメージをサブサンプリングするための係数
auto
(既定値) | 整数 | 整数のベクトル
グラウンド トゥルース データ ソースのイメージをサブサンプリングするための係数。auto
、整数、または整数のベクトルとして指定します。サンプリング係数が N の場合、返される学習データには、グラウンド トゥルース データ ソースのイメージが N 個おきに含まれます。関数は、ラベル データが空のグラウンド トゥルース イメージを無視します。投影された直方体データを使用して SamplingFactor
を設定するには、名前と値の引数 LabelType
を labelType.ProjectedCuboid
に指定しなければなりません。
サンプリングされたデータを使用して、同じシーンとラベルをもつイメージのシーケンスなどの重複データを減らします。これは、学習時間の短縮にも役立ちます。
値 | サンプリング係数 |
---|---|
"auto" | 関数は、ビデオなどのタイムスタンプ付きのデータ ソースを係数 5 でサンプリングします。イメージのコレクションの場合の係数は 1 です。 |
整数 | すべてのデータに適用するサンプリング係数を手動で設定します。 |
整数のベクトル | グラウンド トゥルース オブジェクトの配列を入力すると、関数は対応するベクトル要素で指定されたサンプリング係数を使用します。 |
LabelType
— グラウンド トゥルース データから抽出するラベルのタイプ
"labelType.Rectangle"
(既定値) | "labelType.RotatedRectangle"
| "labelType.ProjectedCuboid"
| 文字ベクトル
グラウンド トゥルース データから抽出するラベルのタイプ。"labelType.Rectangle"
、"labelType.RotatedRectangle"
、または "labelType.ProjectedCuboid"
として指定します。学習させるオブジェクト検出器のタイプと一致するラベルのタイプを使用します。
メモ
関数 trainYOLOv2ObjectDetector
は、"labelType.RotatedRectangle"
をサポートしていません。
WriteLocation
— フォルダーの名前
pwd
(現在の作業フォルダー) (既定値) | string スカラー | 文字ベクトル
抽出されたイメージを書き込むフォルダー名。string スカラーまたは文字ベクトルとして指定します。指定されたフォルダーが存在している必要があります。また、そのフォルダーへの書き込み権限が必要です。
この引数は、次の場合にのみ適用されます。
ビデオ ファイルまたはカスタム データ ソースを使用して作成された
groundTruth
オブジェクト。異なるカスタム
read
関数を指定してimageDatastore
を使用して作成されたgroundTruth
オブジェクトの配列。
次の場合、関数はこの引数を無視します。
入力
groundTruth
オブジェクトがイメージ シーケンス データ ソースから作成された。入力
groundTruth
オブジェクトの配列すべてに、同じカスタムread
関数を使用するイメージ データストアが含まれている。データストアを含む入力
groundTruth
オブジェクトのいずれかで、既定のread
関数を使用している。
ImageFormat
— イメージ ファイル形式
PNG
(既定値) | string スカラー | 文字ベクトル
イメージ ファイル形式。string スカラーまたは文字ベクトルとして指定します。ファイル形式は imwrite
によってサポートされていなければなりません。
この引数は、次の場合にのみ適用されます。
ビデオ ファイルまたはカスタム データ ソースを使用して作成された
groundTruth
オブジェクト。異なるカスタム
read
関数を指定してimageDatastore
を使用して作成されたgroundTruth
オブジェクトの配列。
次の場合、関数はこの引数を無視します。
入力
groundTruth
オブジェクトがイメージ シーケンス データ ソースから作成された。入力
groundTruth
オブジェクトの配列すべてに、同じカスタムread
関数を使用するイメージ データストアが含まれている。データストアを含む入力
groundTruth
オブジェクトのいずれかで、既定のread
関数を使用している。
NamePrefix
— 出力イメージ ファイル名の接頭辞
string スカラー | 文字ベクトル
出力ファイル名の接頭辞。string スカラーまたは文字ベクトルとして指定します。イメージ ファイルは次のように命名されます。
<name_prefix><source_number>_<image_number>.<image_format>
既定の値では、イメージ抽出元のデータ ソースの名前を使用します。ビデオおよびカスタム データ ソースでは strcat(sourceName,"_")
、イメージ データストアでは "datastore"
を使用します。
この引数は、次の場合にのみ適用されます。
ビデオ ファイルまたはカスタム データ ソースを使用して作成された
groundTruth
オブジェクト。異なるカスタム
read
関数を指定してimageDatastore
を使用して作成されたgroundTruth
オブジェクトの配列。
次の場合、関数はこの引数を無視します。
入力
groundTruth
オブジェクトがイメージ シーケンス データ ソースから作成された。入力
groundTruth
オブジェクトの配列すべてに、同じカスタムread
関数を使用するイメージ データストアが含まれている。データストアを含む入力
groundTruth
オブジェクトのいずれかで、既定のread
関数を使用している。
Verbose
— 学習の進行状況を表示するフラグ
true
(1
) (既定値) | false
(0
)
MATLAB コマンド ラインに学習の進行状況を表示するためのフラグ。true
(1
) または false
(0
) として指定します。このプロパティは、ビデオ ファイルまたはカスタム データ ソースを使用して作成された groundTruth
オブジェクトにのみ適用されます。
出力引数
imds
— イメージ データストア
imageDatastore
オブジェクト
イメージ データストア。gTruth
オブジェクトから抽出されたイメージを含む imageDatastore
オブジェクトとして返されます。imds
内のイメージには、注釈付きラベルのクラスが少なくとも 1 つ含まれています。関数は、注釈が付けられていないイメージを無視します。
blds
— ボックス ラベル データストア
boxLabelDatastore
オブジェクト
ボックス ラベル データストア。boxLabelDatastore
オブジェクトとして返されます。データストアには、ROI ラベル名の categorical ベクトルと、M 個の境界ボックスの M 行 4 列の行列が含まれています。境界ボックスの位置とサイズは、[x,y,width,height] 形式の double の M x 4 要素ベクトルとして表されます。
arrds
— 配列データストア
struct
配列
配列データ ストア。struct
配列として返されます。struct
のフィールドには、ボックス ラベル データストア blds
内の対応するラベルの属性とサブラベル名が格納されます。サブラベル データは、サブラベル属性に対応するフィールドとともに、Position
フィールドを使用して struct
にパッケージ化されます。
trainingDataTable
— 学習データの table
table
学習データの table。2 列以上の table として返されます。table の最初の列には、パスを含むイメージ ファイル名が含まれています。imread
でサポートされている任意の形式のグレースケールまたはトゥルーカラー (RGB) イメージを指定できます。残りの各列は、ROI ラベルに対応し、そのラベルのイメージにおける境界ボックスの位置 (最初の列で指定) が含まれます。境界ボックスは、[x,y,width,height] の形式で M 個の境界ボックスの M 行 4 列の行列として指定します。[x,y] は左上隅の位置を指定します。グラウンド トゥルース table の作成には、イメージ ラベラーアプリまたはビデオ ラベラー アプリを使用できます。
出力 table は、入力 gTruth
オブジェクトに存在するサブラベルや属性データを無視します。
バージョン履歴
R2017a で導入R2022b: 3 次元ワールド座標から 2 次元イメージ座標への直方体の射影
3 次元投影された直方体ラベルをサポートするように更新されました。
抽出された属性とサブラベルを 3 番目の出力として返します。属性とサブラベルは、配列データストアとしてパッケージ化されます。
参考
アプリ
関数
trainFastRCNNObjectDetector
|trainFasterRCNNObjectDetector
|trainRCNNObjectDetector
|trainACFObjectDetector
|trainYOLOv2ObjectDetector
|estimateAnchorBoxes
オブジェクト
トピック
- 深層学習用のデータストア (Deep Learning Toolbox)
- オブジェクト検出およびセマンティック セグメンテーション用の学習データ
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)