Sunteți pe pagina 1din 4

{"type":"headsupcheck","


url":"http://www.lightstalki
ng.com/restore-your- 
File Exchange
photos/"} 

Select
Demos from Your Recognition:
"Object Country Deep Learning" Webinar
version 1.0.0.1your
Choose KB) by Johanna
(12.2country Pingel content where available and see local events and offers. Based on your location, we recommend
to get translated
Demos
thatUsed in "Object
you select: Recognition:
United States. Deep Learning and Machine Learning for Computer Vision" Webinar
 10 Ratings
Select United States
233 Downloads 
Updated 02 May 2017
You can also select a location from the following list: View License

Americas Add to Watchlist Download

Canada (English)
Overview Functions
United States (English)

Europe
DeepLearningWebinar/D %% Scene Identification Using Image Data
emo1_BagOfFeatures/ % Image classification involves determining if an image contains some
Belgium (English) Netherlands
% specific object, feature, or activity. The (English)is to
goal of this example
prepareInputFiles(dsObj) % provide a strategy to construct a classifier that can automatically
Denmark (English) % detect which scene we are looking atNorway (English)
Scene_Identification.m
Deutschland (Deutsch) % This example uses function from the Österreich
Computer Vision System Toolbox and
(Deutsch)
% Statistics and Machine Learning
DeepLearningWebinar/D
España (Español) % Copyright (c) 2016, MathWorks, Inc. Portugal (English)
emo2_TransferLearning/
Finland (English) %% Description of the Data Sweden (English)
% The dataset contains 4 scenes: Field, Auditorium, Beach ,Restaurant
France (Français)
Food_Identification.m % The images are photos of the scenesSwitzerland
that have been taken from different
Ireland (English)
readAndPreprocessImage(filena % angles, positions, and different lighting conditions.
Deutsch These variations make
me) % this a challenging task.
Italia (Italiano) %%% English
readFunctionTrain(filename) %%
Luxembourg (English)
readFunctionValidation(filenam % Data needs to be downloaded in order forFrançais
this demo to run
% Please use your own data or download a database
United Kingdomonline
(English)
e) % Here's an example of a good source of scene data
% http://groups.csail.mit.edu/vision/SUN/
DeepLearningWebinar/D
Asia Pacific
emo3_FeatureExtractor/ %% Load image data
Australia (English) % This assumes you have a directory: Scene_Categories
readAndPreprocessImage(filena % with each scene in a subdirectory
India (English) imds = imageDatastore('Scene_Categories',...
me) 'IncludeSubfolders',true,'LabelSource','foldernames') %#ok
New Zealand (English)
Scene_Identification_DL.m
%% Display Class Names and Counts
( ) tbl = countEachLabel(imds) %#ok
( ) categories = tbl.Label;

( ) %% Display Sampling of Image Data


sample = splitEachLabel(imds,16);

montage(sample.Files(1:16));
title(char(tbl.Label(1))); See all countries
%% Show sampling of all data
for ii = 1:4
sf = (ii-1)*16 +1;
ax(ii) = subplot(2,2,ii);
montage(sample.Files(sf:sf+3));
title(char(tbl.Label(ii)));
end
% expandAxes(ax); % this is an optional feature,
% you can download this from the fileexchange as well!
%% Pre-process Training Data: *Feature Extraction using Bag Of Words*
% Bag of features, also known as bag of visual words is one way to extract
converted by Web2PDFConvert.com
% Bag of features, also known as bag of visual words is one way to extract
% features from images. To represent an image using this approach, an image
% can be treated as a document and occurance of visual "words" in images
% are used to generate a histogram that represents an image.
%% Partition 700 images for training and 200 for testing
[training_set, test_set] = prepareInputFiles(imds);
%% Create Visual Vocabulary
tic
bag = bagOfFeatures(training_set,...
'VocabularySize',250,'PointSelection','Detector');
scenedata = double(encode(bag, training_set));
toc
return;
%% Visualize Feature Vectors
img = read(training_set(1), randi(training_set(1).Count));
featureVector = encode(bag, img);

subplot(4,2,1); imshow(img);
subplot(4,2,2);
bar(featureVector);title('Visual Word Occurrences');xlabel('Visual Word Index');ylabel('Frequency');
img = read(training_set(2), randi(training_set(2).Count));
featureVector = encode(bag, img);
subplot(4,2,3); imshow(img);
subplot(4,2,4);
bar(featureVector);title('Visual Word Occurrences');xlabel('Visual Word Index');ylabel('Frequency');

img = read(training_set(3), randi(training_set(3).Count));


featureVector = encode(bag, img);
subplot(4,2,5); imshow(img);
subplot(4,2,6);
bar(featureVector);title('Visual Word Occurrences');xlabel('Visual Word Index');ylabel('Frequency');
img = read(training_set(4), randi(training_set(4).Count));
featureVector = encode(bag, img);
subplot(4,2,7); imshow(img);
subplot(4,2,8);
bar(featureVector);title('Visual Word Occurrences');xlabel('Visual Word Index');ylabel('Frequency');
%% Create a Table using the encoded features
SceneImageData = array2table(scenedata);
sceneType = categorical(repelem({training_set.Description}', [training_set.Count], 1));
SceneImageData.sceneType = sceneType;
%% Use the new features to train a model and assess its performance using
classificationLearner
%% Can we look at Beaches and Fields and see why they are misidentified?
jj = randi(randi(training_set(ii).Count));
imshowpair(read(training_set(2),jj),read(training_set(3),jj),'montage')
title('Beaches vs. Fields');
%% Test out accuracy on test set!

testSceneData = double(encode(bag, test_set));


testSceneData = array2table(testSceneData,'VariableNames',trainedClassifier.RequiredVariables);
actualSceneType = categorical(repelem({test_set.Description}', [test_set.Count], 1));

predictedOutcome = trainedClassifier.predictFcn(testSceneData);
correctPredictions = (predictedOutcome == actualSceneType);
validationAccuracy = sum(correctPredictions)/length(predictedOutcome) %#ok

%% Visualize how the classifier works


ii = randi(size(test_set,2));
jj = randi(test_set(ii).Count);
img = read(test_set(ii),jj);
imshow(img)
% Add code here to invoke the trained classifier
imagefeatures = double(encode(bag, img));
% Find two closest matches for each feature
[bestGuess, score] = predict(trainedClassifier.ClassificationSVM,imagefeatures);
% Display the string label for img
if strcmp(char(bestGuess),test_set(ii).Description)
titleColor = [0 0.8 0];
else
titleColor = 'r';
end
title(sprintf('Best Guess: %s; Actual: %s',...
char(bestGuess),test_set(ii).Description),...

converted by Web2PDFConvert.com
char(bestGuess),test_set(ii).Description),...
'color',titleColor)

Trial software

Explore Products
MATLAB
Simulink
Student Software
Hardware Support
File Exchange

Try or Buy
Downloads
Trial Software
Contact Sales
Pricing and Licensing

Learn to Use
Documentation
Tutorials
Examples
Videos and Webinars
Training

Get Support
Installation Help
Answers
Consulting
Application Status
License Center

About MathWorks
Careers
Newsroom
Social Mission
About MathWorks

MathWorks
Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover...

 United States

converted by Web2PDFConvert.com
Patents
Trademarks
Privacy Policy
Preventing Piracy
Terms of Use
© 1994-2017 The MathWorks, Inc.

Join the conversation

converted by Web2PDFConvert.com