From be060f3416105b95d59741c17824ee8879fb0b9a Mon Sep 17 00:00:00 2001 From: Somdip Dey Date: Wed, 27 Jun 2018 08:53:00 +0100 Subject: [PATCH] updated matlab code --- source/matlab/.DS_Store | Bin 0 -> 6148 bytes source/matlab/vgg16_custom.m | 10 +++-- source/matlab/video_to_images.m | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 source/matlab/.DS_Store create mode 100644 source/matlab/video_to_images.m diff --git a/source/matlab/.DS_Store b/source/matlab/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..67f701c85740f19ed876716d6c51c3e023b0659a GIT binary patch literal 6148 zcmeHKJxc>Y5Pf4(1O$ndmRni{(%9G>Ar{vD0L>R6aN)pQM7#St{z`o_J4$k1VI?9n zVdqU|XXf@E-0ltlne3NiUC_5e}yeZ*xr@ZVqR8r#wkfR99QoqwA6Q)TVjS+tnfqzM&#fHbu0g^m4D9s4VKKQ z$X#uE!za(Uo|RQ;tw1hX6?7FL!9Xw&3*kt4kMRF=Jr;4{2lGEu=9#=Rv8FMN{- zPiOsP;gBL@=wKiiIA%b5U&>I=|66`ColU-lgbD_Nf&a>Y^r!dJ3E$4o)^G2rXKmtm tqe}q)=st33lX*U=&A7s`$*5J-Z|TIi2pA!uf`MOP-~+I&JPrT= literal 0 HcmV?d00001 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 !!!