Skip to content

Commit

Permalink
updated matlab code
Browse files Browse the repository at this point in the history
  • Loading branch information
Somdip Dey committed Jun 27, 2018
1 parent 2ab09ab commit be060f3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
Binary file added source/matlab/.DS_Store
Binary file not shown.
10 changes: 7 additions & 3 deletions source/matlab/vgg16_custom.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: ');
Expand Down
64 changes: 64 additions & 0 deletions source/matlab/video_to_images.m
Original file line number Diff line number Diff line change
@@ -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 !!!

0 comments on commit be060f3

Please sign in to comment.