Main Content

partitionByIndex

Partition augmentedImageDatastore according to indices

Description

auimds2 = partitionByIndex(auimds,ind) partitions a subset of observations in an augmented image datastore, auimds, into a new datastore, auimds2. The desired observations are specified by indices, ind.

example

Examples

collapse all

Load the sample data, which consists of synthetic images of handwritten digits. XTrain is a 28-by-28-by-1-by-5000 array, where:

  • 28 is the height and width of the images.

  • 1 is the number of channels.

  • 5000 is the number of synthetic images of handwritten digits.

load DigitsDataTrain
whos XTrain
  Name         Size                      Bytes  Class     Attributes

  XTrain      28x28x1x5000            31360000  double              

Create an imageDataAugmenter object that specifies preprocessing options for image augmentation, such as resizing, rotation, translation, and reflection. Randomly translate the images up to three pixels horizontally and vertically, and rotate the images with an angle up to 20 degrees.

imageAugmenter = imageDataAugmenter( ...
    RandRotation=[-20,20], ...
    RandXTranslation=[-3 3], ...
    RandYTranslation=[-3 3]);

Create an augmentedImageDatastore using the image data augmented. When you read from the datastore, for example during network training using the trainnet function, the datastore performs image augmentation and resizes the images. The datastore augments the images without saving any images to memory.

imageSize = [64 64 1];
augimds = augmentedImageDatastore(imageSize,XTrain,DataAugmentation=imageAugmenter);

Create a random permutation of the integers one to the total number of images in the datastore.

numObservations = augimds.NumObservations;

Shuffle the images to create a new datastore containing the same images in a random order.

augimds = shuffle(augimds);

Partition the datastore. The partitionByIndex function returns a datastore containing 80% of the images.

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

Partition the datastore using elements of the remaining indices. The partitionByIndex function returns a datastore containing the remaining 20% of the images.

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

Input Arguments

collapse all

Augmented image datastore, specified as an augmentedImageDatastore object.

Indices of observations, specified as a vector of positive integers.

Output Arguments

collapse all

Output datastore, returned as an augmentedImageDatastore object containing a subset of files from auimds.

Version History

Introduced in R2018a