partitionByIndex
インデックスに応じた augmentedImageDatastore
の分割
説明
例
サンプル データを読み込みます。サンプル データは、手書き数字の合成イメージで構成されています。XTrain
は 28×28×1×5000 の配列です。ここで、以下のようになります。
28 はイメージの高さと幅。
1 はチャネルの数。
5000 は手書き数字の合成イメージの数。
load DigitsDataTrain whos XTrain
Name Size Bytes Class Attributes XTrain 28x28x1x5000 31360000 double
サイズ変更、回転、平行移動、反転など、イメージ拡張の前処理オプションを指定する imageDataAugmenter
オブジェクトを作成します。イメージを、水平方向および垂直方向に最大 3 ピクセルまでのランダムな平行移動をさせたり、最大 20 度までの回転をさせたりします。
imageAugmenter = imageDataAugmenter( ... RandRotation=[-20,20], ... RandXTranslation=[-3 3], ... RandYTranslation=[-3 3]);
拡張されたイメージ データを使用して augmentedImageDatastore
を作成します。たとえば、trainnet
関数を使用してネットワークに学習させているときにデータストアから読み取りを行うと、データストアはイメージの拡張を実行し、イメージのサイズを変更します。データストアは、イメージをメモリに保存せずにイメージを拡張します。
imageSize = [64 64 1]; augimds = augmentedImageDatastore(imageSize,XTrain,DataAugmentation=imageAugmenter);
データストアに含まれるイメージの総数を上限とする 1 から始まる整数のランダムな順列を作成します。
numObservations = augimds.NumObservations;
イメージをシャッフルして、同じイメージをランダムな順序で格納する新しいデータストアを作成します。
augimds = shuffle(augimds);
データストアを分割します。partitionByIndex
関数は、イメージの 80% を含むデータストアを返します。
trainAugimds = partitionByIndex(augimds,1:round(0.8*numObservations))
trainAugimds = augmentedImageDatastore with properties: NumObservations: 4000 MiniBatchSize: 128 DataAugmentation: [1×1 imageDataAugmenter] ColorPreprocessing: 'none' OutputSize: [64 64] OutputSizeMode: 'resize' DispatchInBackground: 0
残りのインデックスの要素を使用してデータストアを分割します。partitionByIndex
関数は、残りの 20% のイメージを含むデータストアを返します。
valAugimds = partitionByIndex(augimds,round(0.8*numObservations)+1:numObservations)
valAugimds = augmentedImageDatastore with properties: NumObservations: 1000 MiniBatchSize: 128 DataAugmentation: [1×1 imageDataAugmenter] ColorPreprocessing: 'none' OutputSize: [64 64] OutputSizeMode: 'resize' DispatchInBackground: 0
入力引数
拡張イメージ データストア。augmentedImageDatastore
オブジェクトとして指定します。
観測値のインデックス。正の整数のベクトルとして指定します。
バージョン履歴
R2018a で導入
参考
read
| readall
| readByIndex
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)