Matlab - Use trained net for testing
My project is to recognize ancient coins. I am using Matlab. I already have a feature file which contains both inputs and output. I have trained 3 types of coins using newff and net had been saved. For the three types of coins, I used 01, 10 and 11 as targets. Now I want to use that trained net for testing. I have test images too. I coded like this:
load net.mat;
load features.mat;
testInputs = Features';
out = sim(net,testInputs);
[dummy, I]=max(out);
Value of I
is using to check the coin type. If I
is 1 then type 1, if 2 then type 2 and if 3 t开发者_C百科ype 3. Am I correct? I hard coded these 1,2,3 values because I gave targets as 01, 10 and 11.
if (I == 2)
fprintf('Type1\n');
elseif (I == 1)
fprintf('Type2\n');
elseif (I == 3)
fprintf('Type3\n');
else
fprintf('undefined\n');
end
Although now I input 3 types of test coin images, it either displays 1 or 2 for the value I
. But not 3. Even when I am using the same set of images which are used for training, it also gives either 1 or 2 for the value I
.
Can u please help me?
The second argument of max() will give you the index of the neuron with higher output. If you have only two neurons, which is the case if your targets are [0,1], [1,0] and [1,1] (note only two elements on every target) there will be no way to get a 3 out of that max(). You should try [0,0,1], [0,1,0] and [1,0,0].
On a side note, if you are using tansig as the activation function of the neurons, consider using -1 instead of 0 on the targets, so you can better exploit the non-linearity. Something like [-1,-1,1], [-1,1,-1], [1,-1,-1].
精彩评论