diff --git a/source/matlab/.DS_Store b/source/matlab/.DS_Store new file mode 100644 index 0000000..67f701c Binary files /dev/null and b/source/matlab/.DS_Store differ diff --git a/source/matlab/vgg16_custom.m b/source/matlab/vgg16_custom.m index 6539b73..bd99513 100644 --- a/source/matlab/vgg16_custom.m +++ b/source/matlab/vgg16_custom.m @@ -9,7 +9,7 @@ function vgg16_custom() %Split DataSet into two sets: Training & Validation. Here Split is done on %9:1 ratio. - [imdsTrain,imdsValidation] = splitEachLabel(imds,0.9,'randomized'); + [imdsTrain,imdsValidation] = splitEachLabel(imds,0.75,'randomized'); %Select 9 random image numbers to show numTrainImages = numel(imdsTrain.Labels); @@ -114,9 +114,13 @@ function vgg16_custom() test_imds = imageDatastore('/Users/somdipdey/Documents/MATLAB/Add-Ons/Collections/Deep Learning Tutorial Series/code/AHS/test_dataset', ... 'IncludeSubfolders',true, ... 'LabelSource','foldernames'); - test_augimdsValidation = augmentedImageDatastore(inputSize(1:2),test_imds); + %test_augimdsValidation = + %augmentedImageDatastore(inputSize(1:2),test_imds);%no need to augment + %testing dataset if not needed %%Classify Test Images - [YPred2,scores2] = classify(netTransfer,test_augimdsValidation); + %[YPred2,scores2] = classify(netTransfer,test_augimdsValidation);% use if augmented + %test dataset is used for testing + [YPred2,scores2] = classify(netTransfer,test_imds); %Display Predication and it's score fprintf('\n Testing on a completely new dataset \n'); fprintf('Prediction: %s' , YPred2 , ', Scores: '); diff --git a/source/matlab/video_to_images.m b/source/matlab/video_to_images.m new file mode 100644 index 0000000..0851c5a --- /dev/null +++ b/source/matlab/video_to_images.m @@ -0,0 +1,64 @@ +videosDir = '/Users/somdipdey/Documents/MATLAB/Add-Ons/Collections/Deep Learning Tutorial Series/code/AHS/curated_video' +currDir = pwd +dinfo = dir(videosDir); +dinfo(ismember( {dinfo.name}, {'.', '..'})) = []; %remove . and .. +%dirFlags = [dinfo.isdir] & ~strcmp({dinfo.name},'.') & ~strcmp({dinfo.name},'..'); + + +for k= 1:length(dinfo) + fprintf('Loop started.\n'); + if ~dinfo(k).isdir + continue + end + path = strcat(videosDir,'/',dinfo(k).name) + + currDir + dinfo(k) + videoPath=strcat(path,'/medium_2.mp4') + % shuttleVideo = audiovideo.mmreader(videoPath); + shuttleVideo = VideoReader(videoPath); + + frVidInfo=get(shuttleVideo); + numberOfFrames = shuttleVideo.NumberOfFrames + vidHeight = shuttleVideo.Height; + vidWidth = shuttleVideo.Width; + framesToRead = 1:12:numberOfFrames + % initialize a matrix for all frames to be read + % allFrames = zeros(vidHeight, vidWidth, 3, length(framesToRead)); + + img_dir = strcat('img/',dinfo(k).name) + path = fullfile(currDir,img_dir) + if exist(path, 'dir') + + if length(dir([path '/*.jpg']))>1 + continue +% else +% delete(path,'\*.fig') + end + else + mkdir(path) + end + % read in the frames + for k=1:length(framesToRead) + + frameIdx = framesToRead(k); + + currentFrame = read(shuttleVideo,frameIdx); + filename = sprintf('%d.jpg',k-1); + % filename = [sprintf('%03d',ii) '.jpg']; + fullname = fullfile(currDir,img_dir,filename); + imwrite(currentFrame,fullname); + +% if k==1 +% % cast the all frames matrix appropriately +% allFrames = cast(allFrames, class(currentFrame)); +% end +% +% allFrames(:,:,:,k) = currentFrame; + end + +end + + +% Code will end adnormally beacuse it will search video in images folder as +% well !!!