skin detection by BP
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all Kindly i implement below code for RGB skin color detection , 3 input vectors RGB ,1 output vector ( 0 non - skin , 1 skin ) but the outcomes doesn't satisfy me, does NN not trained well or i have wrong , i really appreciate your help
% p=[119 88 82 204 10;79 59 73 150 10 ;53 55 68 103 20 ];
t=[1 1 1 1 0];
net=newff([0 255 ; 0 1],[5,1],{'logsig' 'tansig'});
net.numInputs = 3; % set number of inputs
net.inputs{1}.size = 1; % assign 2 to input size
net.inputs{2}.size = 1;
net.inputs{3}.size = 1;
net.trainParam.show=1;
net.trainParam.epochs=1000;
net.trainParam.goal=0.001;
net.trainParam.lr=0.1;
[net,tr]=train(net,p,t);
im=imread('./test3.jpg');
h=size(im,1);
w=size(im,2);
r=im(:,:,1);
g=im(:,:,1);
b=im(:,:,1);
r=double(reshape(r,1,h*w));
g=double(reshape(g,1,h*w));
b=double(reshape(b,1,h*w));
y=sim(net,[r;g;b]);
y=double(reshape(y,h,w));
imshow(y);
2 件のコメント
Walter Roberson
2013 年 10 月 21 日
編集済み: Walter Roberson
2013 年 10 月 21 日
What is "BP" in your Title ?
Have you considered feeding it more examples of non skin tones? Skin tones do not fall into a nice RGB or HSV subsection, so to do a good job you need enough examples near the boundaries (on both sides) for it to be able to deduce where the boundaries are.
採用された回答
Greg Heath
2013 年 10 月 23 日
From a strictly coding perspective:
p=[119 88 82 204 10;79 59 73 150 10 ;53 55 68 103 20 ];
t=[1 1 1 1 0];
net=newff([0 255 ; 0 1],[5,1],{'logsig' 'tansig'});
%ERROR!, the first input should be 3-D, not 2-D
% Warning: NEWFF used in an obsolete way.
% See help for NEWFF to update calls to the new argument list.
%
% GEH: To be sure of the defaults for this VERY obsolete function, run again with the 2-D error corrected and ending semicolon removed. Then compare properties with the more recent, but also, obsolete version:
net = newff( p, t, 5,{'logsig' 'tansig'});
>> help newff
newff Create a feed-forward backpropagation network.
Obsoleted in R2010b NNET 7.0. Last used in R2010a NNET 6.0.4.
The recommended function is feedforwardnet.
% I don't agree with the recommendation. Use patternnet for classification/pattern-recognition and fitnet for regression/curvefitting. They both call feedforwardnet. The fitnet/patternnet/feedforwardnet trio have replaced the obsolete newfit/newpr/newff trio.
%The more recent version of newff automatically removes constant rows from input and output matrices, normalizes inputs and outputs to [-1,-1], divides the data into train/validation/test subsets with divison ratios 0.7/0.15/0.15 and uses tansig(i.e.,tanh) transfer functions for both hidden and output layers.
However, for the ancient version you are using, there is no automatic row removal, normalization, or data division. Furthermore, the default hidden and output transfer functions are tanh and linear (purelin).
If you cannot get the more recent version of newff (preferably newpr for classification) or better yet, the current patternnet, then do the following
1. Use mapminmax to normalize inputs to [-1,-1]
2. Use odd polarity tansig hidden transfer functions
3. Use logsig output transfer functions for [ 0 1 ] probabilistic outputs.
4. To avoid overfitting, try to choose the number of hidden layer transfer functions, H, so that the total number of unknown weights, Nw, are much less than the number of training equations Ntrneq.
For example, suppose you did not divide the data into trn/val/tst subsets:
{ I N ] = size(p) % [ 3 5 ]
[ O N ] = size(t) % [ 1 5 ]
Ntrn = N % 5
Ntrneq = N*O % 5
and the number of unknown weights is
Nw = (I+1)*H+(H+1)*O
then there is no overfitting (Nw < Ntrneq) if H <= Hub ( upper bound) where
Hub = -1 + ceil( (Ntrneq-O) / (I+O+1) ) % 0
Choosing H = 0 leads to a multinomial logistic regression model (Google Wikipedia\logistic_regression)
net = newff( [-1,1; -1,1, -1,1 ], [ [], 1 ], { 'logsig'});
or the later version
net = newff( p, t,[],{'logsig'} );
Hope this helps.
Thank you for formally accepting my answer.
Greg
P.S. For a real world problem you will need a hidden layer and much more data to prevent overfitting.
P.P.S. Try one or more of the MATLAB classification data sets in
help nndatsets.
For example, the crab gender classification dataset has 6 inputs and 2 outputs. If you show me your solutions, I'll show you mine!
help crab_dataset
6 件のコメント
その他の回答 (1 件)
Image Analyst
2013 年 10 月 21 日
Walter is right. The gamut for skin color does not fall nicely into a region in any colorspace that can be segmented nicely by thresholding. For all skin tones that you encounter, the gamut is banana or boomerang shaped. For any one individual you might be able to threshold and get their skin but it will work only for that one individual, not for any arbitrary individual of any race and any color of lighting and any level of exposure. For that you will need more sophisticated algorithms to carve out the skin gamut's true shape from the total possible gamut. But I don't know neural networks so I can say anything about what you are doing. It seems reasonable that if you were to train a NN on one image and then test it on the same image, it should get the skin. Greg Heath will probably respond to your NN question shortly.
参考
カテゴリ
Help Center および File Exchange で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!