My pictures have a format of [227 227 1] so I had the idea to triplicate my processed pictures and put them back into one to get a format of [227 227 3], how can I do this?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I'm doing a project where I am writing a hand gesture detection program but i've run into some problems.
I'm getting my picture through a webcam and processing them to be black and white and have a format of [227 227 1]. Unfortunally its just not working with my self written network.
Now I want to try a pretraind network but this requires a format of [227 227 3] but my pictures are still black and withe so they have a format of [227 227 1] so I had the idea to triplicate my processed picture and put them back into one to get a format of [227 227 3]
Does someone have and idea how I could do that?
Or could help me to figure out why my selfwritten network isn't working?
Attached you can find the Network, many thanks in advance!!
allImages = imageDatastore('Handgesten_BW','IncludeSubfolders',true, 'LabelSource','foldernames');
[imdsTrain,imdsVal] = splitEachLabel(allImages,0.7,'randomized');
imageSize = [227 227 1];
OutputSize = 7;
%Layers
layers = [
imageInputLayer(imageSize,"Name","imageinput")
convolution2dLayer([11 11],96,"Name","conv1","BiasLearnRateFactor",2,"Stride",[4 4])
reluLayer("Name","relu1")
crossChannelNormalizationLayer(5,"Name","norm1","K",1)
maxPooling2dLayer([3 3],"Name","pool1","Stride",[2 2])
groupedConvolution2dLayer([5 5],128,2,"Name","conv2","BiasLearnRateFactor",2,"Padding",[2 2 2 2])
reluLayer("Name","relu2")
crossChannelNormalizationLayer(5,"Name","norm2","K",1)
maxPooling2dLayer([3 3],"Name","pool2","Stride",[2 2])
convolution2dLayer([3 3],384,"Name","conv3","BiasLearnRateFactor",2,"Padding",[1 1 1 1])
reluLayer("Name","relu3")
groupedConvolution2dLayer([3 3],192,2,"Name","conv4","BiasLearnRateFactor",2,"Padding",[1 1 1 1])
reluLayer("Name","relu4")
groupedConvolution2dLayer([3 3],128,2,"Name","conv5","BiasLearnRateFactor",2,"Padding",[1 1 1 1])
reluLayer("Name","relu5")
maxPooling2dLayer([3 3],"Name","pool5","Stride",[2 2])
fullyConnectedLayer(4096,"Name","fc6","BiasLearnRateFactor",2)
reluLayer("Name","relu6")
dropoutLayer(0.5,"Name","drop6")
fullyConnectedLayer(4096,"Name","fc7","BiasLearnRateFactor",2)
reluLayer("Name","relu7")
dropoutLayer(0.5,"Name","drop7")
fullyConnectedLayer(OutputSize,"Name","fc8","BiasLearnRateFactor",2)
softmaxLayer("Name","prob")
classificationLayer("Name","classoutput")];
%Train/Val
augmenter = imageDataAugmenter( ...
'RandRotation',[-45 45], ...
'RandYReflection', true, ...
'RandScale',[0.8,1.2]);
augimdsTrain = augmentedImageDatastore(imageSize,imdsTrain,'DataAugmentation',augmenter);
augimdsVal = augmentedImageDatastore(imageSize,imdsVal,'DataAugmentation',augmenter);
%Options
options = trainingOptions('sgdm',...
'MiniBatchSize',32, ...
'MaxEpochs',15,...
'InitialLearnRate',0.001,...
'ValidationData',augimdsVal, ...
'ValidationFrequency',20,...
'Verbose',false, ...
'executionenvironment','gpu',...
'Shuffle','every-epoch', ...
'Plots','training-progress');
%'LearnRateSchedule','piecewise',...
%'LearnRateDropFactor',0.5,...
%'LearnRateDropPeriod',25,...
% crossChannelNormalizationLayer(5,'K',1), ...
Netzwerk = trainNetwork(augimdsTrain,layers,options);
save Netzwerk
1 commentaire
Jan
le 12 Juin 2021
"format of [227 227 1]"
This is not possible in Matlab. Trailing dimensions of length 1 (except for the 2nd dimension) vanish automatically:
x = rand(277, 277, 1);
size(x)
What exactly does this mean: "not working with my self written network"? This detail is important, so please share it.
Réponses (2)
Image Analyst
le 12 Juin 2021
Here is the way I usually use
rgbImage = cat(3, grayImage, grayImage, grayImage);
0 commentaires
DGM
le 12 Juin 2021
To rearrange a single-channel intensity image into a grayscale RGB image, you can just do
Argb = repmat(Aint,[1 1 3]);
I don't know if it would be possible/practical or more efficient to find a way to process the single-channel images. I don't know anything about the rest of your code or the training topic.
0 commentaires
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!