How to know the data set after augment?

7 views (last 30 days)
Hello everyone,
I was developed the coding for augmented my data for trainning process using 3D U-Net network. But I dont know how to find the addition data after augment? Because I checked in workspace but not found. Below is my coding, the function @augment3dPatch is for augment data
Also I attached the function for running my coding.
The data for image training (ImagesTr), groundtruthlabeling training (LabelsTr), image validation (imagesVal ), groundtruth validation (labelsVal) can download thru this link https://drive.google.com/drive/folders/176Ffn3d-61HFYiK7ywFFD9rRuzmXnN26?usp=share_link
clc
clear all
close all
%testDataimages
DATASetDir = fullfile('C:\Users\Akmal\Desktop\NEW 3D U NET');
IMAGEDir = fullfile(DATASetDir,'ImagesTr');
volReader = @(x) matRead(x);
volds = imageDatastore(IMAGEDir, ...
'FileExtensions','.mat','ReadFcn', volReader);
% labelReader = @(x) matread(x);
matFileDir = fullfile('C:\Users\Akmal\Desktop\NEW 3D U NET\LabelsTr');
classNames = ["background", "tumor"];
pixelLabelID = [0 1];
% pxds = (LabelDirr,classNames,pixelLabelID, ...
% 'FileExtensions','.mat','ReadFcn',labelReader);
pxds = pixelLabelDatastore(matFileDir,classNames,pixelLabelID, ...
'FileExtensions','.mat','ReadFcn',@matRead);
volume = preview(volds);
label = preview(pxds);
up1 = uipanel;
h = labelvolshow(label, volume, 'Parent', up1);
h.CameraPosition = [4 2 -3.5];
h.LabelVisibility(1) = 0;
h.VolumeThreshold = 0.5;
volumeViewer(volume, label)
patchSize = [128 128 64];
patchPerImage = 16;
miniBatchSize = 8;
patchds = randomPatchExtractionDatastore(volds,pxds,patchSize, ...
'PatchesPerImage',patchPerImage);
patchds.MiniBatchSize = miniBatchSize;
%% AUGMENT DATA FOR TRAINING
dsTrain = transform(patchds,@augment3dPatch);
volLocVal = fullfile('C:\Users\Akmal\Desktop\NEW 3D U NET\imagesVal');
voldsVal = imageDatastore(volLocVal, ...
'FileExtensions','.mat','ReadFcn',volReader);
lblLocVal = fullfile('C:\Users\Akmal\Desktop\NEW 3D U NET\labelsVal');
pxdsVal = pixelLabelDatastore(lblLocVal,classNames,pixelLabelID, ...
'FileExtensions','.mat','ReadFcn',volReader);
dsVal = randomPatchExtractionDatastore(voldsVal,pxdsVal,patchSize, ...
'PatchesPerImage',patchPerImage);
dsVal.MiniBatchSize = miniBatchSize;
%% AUGMENT DATA FOR VALIDATION
dsVal = transform(patchds,@augment3dPatch);
inputSize = [128 128 64];
numClasses = 2;
encoderDepth = 2;
lgraph = unet3dLayers(inputSize,numClasses,'EncoderDepth',encoderDepth,'NumFirstEncoderFilters',16)
figure,plot(lgraph);

Accepted Answer

Walter Roberson
Walter Roberson on 26 Feb 2023
But I dont know how to find the addition data after augment? Because I checked in workspace but not found.
Augmented data is generated internally and is not stored after it is used.If you need it then you can use readall()

More Answers (1)

Askic V
Askic V on 25 Feb 2023
Edited: Askic V on 25 Feb 2023
This is an extract from the documentation:
% transform Create a new datastore that applies a function to the
% data read from all input datastores.
%
% DSNEW = transform(DS, transformFcn) transforms an input
% Datastore, DS, given an input function, transformFcn. The
% transform function has the syntax:
%
% dataOut = FCN(dataIn);
%
% where FCN is a function that takes the dataIn returned by
% read of DS and returns a modified form of that data,
% dataOut.
In your case the new datastorage after augmenting will be dsTrain
How you can inspect the newdata depends on what transform function do.
For example, this is a simple case of image resizing as transformFcn
imds = imageDatastore('peppers.png');
img1 = read(imds); % reads theimage
subplot(211)
imshow(img1)
newDS = transform(imds,@(x) imresize(x, [120, 120]));
imgOut = read(newDS);
subplot(212)
imshow(imgOut);
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char imds 1x1 8 matlab.io.datastore.ImageDatastore img1 384x512x3 589824 uint8 imgOut 120x120x3 43200 uint8 newDS 1x1 8 matlab.io.datastore.TransformedDatastore
As you can see, I need to know how to read the data behind, because datastore is just a pointer to location where the data is.
I hope this example will help you figuring out how exactly to inspect your data.
  2 Comments
mohd akmal masud
mohd akmal masud on 26 Feb 2023
I see..you means is I need to read the dsTrain?
mohd akmal masud
mohd akmal masud on 26 Feb 2023
as you can see in attched article, page 7, the augmented data become 2280 from the original data set 112.
Thats I need to know in my coding.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!