このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
オブジェクト検出器用の学習データの作成
[
は、指定されたグラウンド トゥルースからイメージ データストアとボックス ラベル データストアの学習データを作成します。imds
,blds
] = objectDetectorTrainingData(gTruth
)
combine
(imds
,blds
) を使用してイメージとボックス ラベルのデータストアを統合し、学習に必要なデータストアを作成することができます。統合されたデータストアは、trainACFObjectDetector
、trainYOLOv2ObjectDetector
、trainFastRCNNObjectDetector
、trainFasterRCNNObjectDetector
、trainRCNNObjectDetector
などの学習関数で使用します。
この関数は、複数の MATLAB® ワーカーを使用する並列計算をサポートします。Computer Vision Toolbox の基本設定 ダイアログを使用して並列計算を有効にします。
は、指定されたグラウンド トゥルースから学習データの table を返します。trainingDataTable
= objectDetectorTrainingData(gTruth
)gTruth
は、groundTruth
オブジェクトの配列です。table は、Computer Vision Toolbox™ の学習関数を使用したオブジェクト検出器の学習に使用できます。
___ = objectDetectorTrainingData(
は、1 つ以上の名前と値のペアの引数で追加オプションが指定された学習データの table を返します。gTruth
,Name,Value
)gTruth
の groundTruth
オブジェクトを、ビデオ ファイル、カスタム データ ソース、または異なるカスタム読み取り関数を指定した imageDatastore
オブジェクトを使用して作成する場合、任意の組み合わせの名前と値のペアの引数を指定できます。イメージ コレクションまたはイメージ シーケンス データ ソースから groundTruth
オブジェクトを作成する場合は、名前と値のペアの引数 'SamplingFactor
' しか指定できません。
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 ベースの一時停止標識用オブジェクト検出器を学習させます。
MATLAB パスにイメージを含むフォルダーを追加します。
imageDir = fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'stopSignImages'); addpath(imageDir);
グラウンド トゥルース データを読み込みます。これには、一時停止標識と自動車のデータが含まれます。
load('stopSignsAndCarsGroundTruth.mat','stopSignsAndCarsGroundTruth')
ラベル定義を表示して、グラウンド トゥルースに含まれるラベル タイプを確認します。
stopSignsAndCarsGroundTruth.LabelDefinitions
学習用の一時停止標識データを選択します。
stopSignGroundTruth = selectLabels(stopSignsAndCarsGroundTruth,'stopSign');
一時停止標識オブジェクト検出器のための学習データを作成します。
trainingData = objectDetectorTrainingData(stopSignGroundTruth); summary(trainingData)
Variables: imageFilename: 41×1 cell array of character vectors stopSign: 41×1 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 30.3579 seconds.
ACF ベースの検出器をサンプル イメージでテストします。
I = imread('stopSignTest.jpg');
bboxes = detect(acfDetector,I);
検出したオブジェクトを表示します。
annotation = acfDetector.ModelName;
I = insertObjectAnnotation(I,'rectangle',bboxes,annotation);
figure
imshow(I)
パスからイメージ フォルダーを削除します。
rmpath(imageDir);
学習データを使用して、ACF ベースの車両用オブジェクト検出器を学習させます。
imageDir = fullfile(matlabroot,'toolbox','driving','drivingdata','vehiclesSequence'); addpath(imageDir);
グラウンド トゥルース データを読み込みます。
load vehicleGroundTruth.mat
車両用オブジェクト検出器のための学習データを作成します。
trainingData = objectDetectorTrainingData(gTruth,'SamplingFactor',2);
ACF ベースのオブジェクト検出器を学習させます。
acfDetector = trainACFObjectDetector(trainingData,'ObjectTrainingSize',[20 20]);
ACF Object Detector Training The training will take 4 stages. The model size is 20x20. 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 71 positive examples and 355 negative examples...Completed. The trained classifier has 68 weak learners. -------------------------------------------- Stage 2: Sample negative examples(~100% Completed) Found 76 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 71 positive examples and 355 negative examples...Completed. The trained classifier has 120 weak learners. -------------------------------------------- Stage 3: Sample negative examples(~100% Completed) Found 54 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 71 positive examples and 355 negative examples...Completed. The trained classifier has 170 weak learners. -------------------------------------------- Stage 4: Sample negative examples(~100% Completed) Found 63 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 71 positive examples and 355 negative examples...Completed. The trained classifier has 215 weak learners. -------------------------------------------- ACF object detector training is completed. Elapsed time is 28.4547 seconds.
ACF 検出器をテスト イメージでテストします。
I = imread('highway.png'); [bboxes, scores] = detect(acfDetector,I,'Threshold',1);
分類スコアが最も高い検出を選択します。
[~,idx] = max(scores);
検出したオブジェクトを表示します。
annotation = acfDetector.ModelName;
I = insertObjectAnnotation(I,'rectangle',bboxes(idx,:),annotation);
figure
imshow(I)
パスからイメージ フォルダーを削除します。
rmpath(imageDir);
gTruth
— グラウンド トゥルース データgroundTruth
オブジェクトの配列グラウンド トゥルース データ。スカラー、または groundTruth
オブジェクトの配列として指定します。groundTruth
オブジェクトを使用して、既存のグラウンド トゥルース データからグラウンド トゥルース オブジェクトを作成できます。
並列計算を有効にして groundTruth
のカスタム データ ソースを使用すると、リーダー関数は MATLAB ワーカーのプールを使用してデータ ソースからイメージを並列で読み取ると想定されます。
オプションの引数 Name,Value
のコンマ区切りペアを指定します。Name
は引数名で、Value
は対応する値です。Name
は引用符で囲まなければなりません。Name1,Value1,...,NameN,ValueN
のように、複数の名前と値のペアの引数を、任意の順番で指定できます。
'SamplingFactor'
,5
'SamplingFactor'
— イメージをサブサンプリングするための係数'auto'
(既定値) | 整数 | 整数のベクトルグラウンド トゥルース データ ソースのイメージをサブサンプリングするための係数。'auto'
、整数、または整数のベクトルとして指定します。サンプリング係数が N の場合、返される学習データには、グラウンド トゥルース データ ソースのイメージが N 個おきに含まれます。関数は、ラベル データが空のグラウンド トゥルース イメージを無視します。
値 | サンプリング係数 |
---|---|
'auto' | サンプリング係数 N は、タイムスタンプ付きのデータ ソースの場合は 5 、イメージ コレクションの場合は 1 です。 |
整数 | gTruth のすべてのグラウンド トゥルース データ ソースは、同一のサンプリング係数 N でサンプリングされます。 |
整数のベクトル | gTruth の k 番目のグラウンド トゥルース データ ソースは、サンプリング係数 N(k) でサンプリングされます。 |
'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 スカラーまたは文字ベクトルとして指定します。イメージ ファイルは次のように命名されます。
<name_prefix><source_number>_<image_number>.<image_format>
既定の値では、イメージ抽出元のデータ ソースの名前を使用します。ビデオおよびカスタム データ ソースでは strcat(sourceName,'_')
、イメージ データストアでは 'datastore'
を使用します。
この引数は、次の場合にのみ適用されます。
ビデオ ファイルまたはカスタム データ ソースを使用して作成された groundTruth
オブジェクト。
異なるカスタム read
関数を指定して imageDatastore
を使用して作成された groundTruth
オブジェクトの配列。
次の場合、関数はこの引数を無視します。
入力 groundTruth
オブジェクトがイメージ シーケンス データ ソースから作成された。
入力 groundTruth
オブジェクトの配列すべてに、同じカスタム read
関数を使用するイメージ データストアが含まれている。
データストアを含む入力 groundTruth
オブジェクトのいずれかで、既定の read
関数を使用している。
'Verbose'
— 学習の進行状況を表示するフラグtrue
(既定値) | false
MATLAB コマンド ラインに学習の進行状況を表示するためのフラグ。true
または false
として指定します。このプロパティは、ビデオ ファイルまたはカスタム データ ソースを使用して作成された groundTruth
オブジェクトにのみ適用されます。
imds
— イメージ データストアimageDatastore
オブジェクトイメージ データストア。gTruth
オブジェクトから抽出されたイメージを含む imageDatastore
オブジェクトとして返されます。imds
内のイメージには、注釈付きラベルのクラスが少なくとも 1 つ含まれています。関数は、注釈が付けられていないイメージを無視します。
blds
— ボックス ラベル データストアboxLabelDatastore
オブジェクトボックス ラベル データストア。boxLabelDatastore
オブジェクトとして返されます。データストアには、ROI ラベル名の categorical ベクトルと、M 個の境界ボックスの M 行 4 列の行列が含まれています。境界ボックスの位置とサイズは、[x,y,width,height] 形式の double の M x 4 要素ベクトルとして表されます。
trainingDataTable
— 学習データの table学習データの table。2 列以上の table として返されます。table の最初の列には、パスを含むイメージ ファイル名が含まれています。imread
でサポートされている任意の形式のグレースケールまたはトゥルーカラー (RGB) イメージを指定できます。残りの各列は、ROI ラベルに対応し、そのラベルのイメージにおける境界ボックスの位置 (最初の列で指定) が含まれます。境界ボックスは、[x,y,width,height] の形式で M 個の境界ボックスの M 行 4 列の行列として指定します。[x,y] は左上隅の位置を指定します。グラウンド トゥルース table の作成には、イメージ ラベラーアプリまたはビデオ ラベラー アプリを使用できます。
出力 table は、入力 gTruth
オブジェクトに存在するサブラベルや属性データを無視します。
estimateAnchorBoxes
| trainACFObjectDetector
| trainFasterRCNNObjectDetector
| trainFastRCNNObjectDetector
| trainRCNNObjectDetector
| trainYOLOv2ObjectDetector
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
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: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.