I am confused about how features in cnn works.
Lets say that I create simple CNN in matlab.
layers = [imageInputLayer([imgSize imgSize 1]);
convolution2dLayer(5,6);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
convolution2dLayer(5,12);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
fullyConnectedLayer(numOfClasses);
softmaxLayer();
classificationLayer()];
Now I want to see feature map of conv. layers.
layer = 5; % THIS IS SECOND CONV LAYER
name = net.Layers(layer).Name;
channels = 1:12;
I = deepDreamImage(net,name,channels,'PyramidLevels',12);
figure
I = imtile(I,'ThumbnailSize',[64 64]);
imshow(I)
title(['Layer ',name,' Features'],'Interpreter','none')
What I don't understand is that for what image is that feature map.
I mean I am using not mnist dataset and that feature map tells me nothing.
From what I understand it should be some parts of image of "A" for example.
Is there any way how can I found out for what image is this feature map?
Related
A hardware design does calculate a normalised hog feature vector, which I want to visualise with the Matlab Hog library.
fpga_normArr = 'Output_Norm_FPGA.txt';
delimiterIn = '\n';
headerlinesIn = 0;
A = importdata(fpga_normArr,delimiterIn,headerlinesIn);
% want to give following function extractHOGFeatures "A" Vector as Input .. ?
img = imread('output_cropped.jpeg');
[_, hogVisualization] = extractHOGFeatures(fpga_normArr);
%override the hogVisualization output and plot the modified object?
plot(hogVisualization)
Is there a function in Matlab, which is able to plot a given feature vector?
Edit: I'm open for alternative approaches, perhabs on different platforms
This question already has an answer here:
Matlab Grayscale Normalization
(1 answer)
Closed 5 years ago.
I'm a newer on machine learning and now trying to train a CNN on MNIST.
I have 60k png training set of MNIST, but the Layer class, the imageinputlayer(), it can only zero-center the image, and can't normalize it.
what should I do to scale the image input to 0¬1?
What I mean is: I want deploy a image normalization Layer on the Class Layer when using function trainNetwork() to train a CNN.
in the document of MATLAB: https://cn.mathworks.com/help/nnet/examples/create-simple-deep-learning-network-for-classification.html
There is a demo code
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
digitData = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
[trainDigitData,testDigitData] = splitEachLabel(digitData, ...
trainingNumFiles,'randomize');
layers = [imageInputLayer([28 28 1])
convolution2dLayer(5,20)
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',15, ...
'InitialLearnRate',0.0001);
convnet = trainNetwork(trainDigitData,layers,options);
as we all know, the png image data is int type from 0 to 255.
but in the same time, the input of a cnn deep learning need to be normalized to [0-1]
the normalization options on the class imageInputLayer(), is zero center (data/mean of data)only, don't have a scale normalization options(data/255).
so how could I add a normalization Layer to the Layer structure?
or there is no need to do a normalization for the training set?
Maybe you mean this? This is how I preprocessing the imdb data and it works for my images. The data is stored as (dim1, dim2, sample_size) form
imdb.images.data = (imdb.images.data-min(imdb.images.data(:)))/(max(imdb.images.data(:)-min(imdb.images.data(:))));
imageMean = mean(imdb.images.data,3);
for j= 1:size(imdb.images.data,3)
imdb.images.data(:,:,j) = imdb.images.data(:,:,j) - imageMean ;
end
I am having svm training with several images. This is my first project with SVM. I am extracting features with HOG feature extraction. Training features and label their locations 1 if it is on the horizon line, 0 if it is on the background. I have 74 images for training and 7 images for testing. Unfortunately, I can't go above 50 percent accuracy. I have changed image sizes, I have played cell sizes in feature extraction. It does not change that much. What can I try? And what is the ideal dataset number, how many images for training and testing? For example in one image it predicts all correct in next image all wrong.
This is how I am calculating accuracy;
%%%%% Evaluation
% Testing Data
hfsTest = vertcat(dataset.HorizonFeatsTest{:});
bfsTest = vertcat(dataset.BgFeatsTest{:});
test_data = [hfsTest;bfsTest];
% Labels
hlabelTest = ones(size(hfsTest,1),1);
blabelTest = zeros(size(bfsTest,1),1);
test_label = [hlabelTest;blabelTest];
Predict_label = vertcat(results.predicted_label{:});
acc = numel(find(Predict_label==test_label))/length(test_label);
disp(['Accuracy ', num2str(acc)]);
%done
% Training Data
hfs = vertcat(dataset.HorizonFeats{:});
bfs = vertcat(dataset.BgFeats{:});
train_data = [hfs;bfs];
% Labels
hlabel = ones(size(hfs,1),1);
blabel = zeros(size(bfs,1),1);
train_label = [hlabel;blabel];
%%%
% do training ...
svmModel = svmtrain(train_data, train_label,'BoxConstraint',2e-1);
and I have used Predict_label_image = svmclassify (svmModel, image_feats); for testing.
You need to do a lot of tunning. Here in the documentation you have all the hyperparameters you can play with. I'll start with a rbf kernel and trying [0.01, 0.1, 1, 10] for BoxConstraint.
I'm afraid you can't expect svm to work if you don't try different hyperparameter configurations.
I am working on a fingerprint recognition system, I need to extract pores which are present in the ridges.During my research I read that a blob detection technique can separate the pores from the ridges.However when I am applying a Gaussian Filter, it is smoothing the image. Also the DoG results in another similar image. If this is the right approach then where am I going wrong?
You actually need to apply a gaussian filter with 2 different sets of parameters, then subtract the filters and perform a convolution of the input image with that new filter, i.e. the difference of gaussians.
Here is an example with the coins.png demo image...The code is commented; don't hesitate to play with the parameters to see how that affects the output:
clear
clc
Im = imread('coins.png');
[r,c,~] = size(Im);
%// Initialize 3d array containing 3 images.
FilteredIm = zeros(r,c,3);
%// Try with 3 different kernel sizes
GaussKernel = [7 11 15];
figure;
subplot(2,2,1)
imshow(Im);
title('Original image');
TitleText = cell(1,numel(GaussKernel));
%// Apply Gaussian filter with 3 different kernel sizes/sigma values.
for k = 1:numel(GaussKernel)
%// Kernel sizes change but sigma values stay the same for
%// simplicity...you can play around with them of course.
GaussFilt1 = fspecial('Gaussian', GaussKernel(k), 12);
GaussFilt2 = fspecial('Gaussian', GaussKernel(k), 4);
%// Subtract the filters
DiffGauss = GaussFilt1 - GaussFilt2;
%// Perform convoluton to get filtered image
FilteredIm(:,:,k) = conv2(double(Im), DiffGauss, 'same');
%// Display
subplot(2,2,k+1)
imshow(FilteredIm(:,:,k));
TitleText{k} = sprintf('Filtered- Kernel of %i',GaussKernel(k));
title(TitleText{k});
end
Output:
Now for your application you probably need to play around with the kernel size and sigma parameters provided to fspecial. Good luck!
I am doing a project to detect people in crowd using HOG-LBP. I want to make it for real-time application. I've read in some references, integral image/histogram can increase the speed of the performance from sliding window detection. I want to ask, how to implement integral image on my sliding window detection:
here is the code for integral image from matlab:
A = (cumsum(cumsum(double(img)),2));
and here my sliding window detection code:
im = strcat ('C:\Documents\Crowd_PETS09\S1\L1\Time_13-57\View_001\frame_0150.jpg');
im = imread (im);
figure (1), imshow(im);
win_size= [32, 32];
[lastRightCol lastRightRow d] = size(im);
counter = 1;
%% Scan the window by using sliding window object detection
% this for loop scan the entire image and extract features for each sliding window
% Loop on scales (based on size of the window)
for s=1
disp(strcat('s is',num2str(s)));
X=win_size(1)*s;
Y=win_size(2)*s;
for y = 1:X/4:lastRightCol-Y
for x = 1:Y/4:lastRightRow-X
%get four points for boxes
p1 = [x,y];
p2 = [x+(X-1), y+(Y-1)];
po = [p1; p2] ;
% cropped image based on the four points
crop_px = [po(1,1) po(2,1)];
crop_py = [po(1,2) po(2,2)];
topLeftRow = ceil(min(crop_px));
topLeftCol = ceil(min(crop_py));
bottomRightRow = ceil(max(crop_px));
bottomRightCol = ceil(max(crop_py));
cropedImage = im(topLeftCol:bottomRightCol,topLeftRow:bottomRightRow,:);
%Get the feature vector from croped image
HOGfeatureVector{counter}= getHOG(double(cropedImage));
LBPfeatureVector{counter}= getLBP(cropedImage);
LBPfeatureVector{counter}= LBPfeatureVector{counter}';
boxPoint{counter} = [x,y,X,Y];
counter = counter+1;
x = x+2;
end
end
end
where should i put the integral image code?
i am really appreciate, if someone can help me to figure it out.
Thank you.
The integral image is most suited for the Haar-like features. Using it for HOG or LBP would be tricky. I would suggest to first get your algorithm working, and then think about optimizing it.
By the way, the Computer Vision System Toolbox includes the extractHOGFeatures function, which would be helpful. Here's an example of training a HOG-SVM classifier to recognize hand-written digits. Also there is a vision.PeopleDetector object, which uses a HOG-SVM classifier to detect people. You could either use it directly for your project, or use it to evaluate performance of your own algorithm.