[Solved] How to use the custom neural network function in the MATLAB for images [closed]


If you look at the feedforwardnet MATLAB help page there is this example:

[x,t] = simplefit_dataset;
net = feedforwardnet(10);
net = train(net,x,t);
view(net)
y = net(x);
perf = perform(net,y,t)

This is almost what you want. The feedforwardnet can take an array of different hidden layer sizes, so we can do:

    net = feedforwardnet([2 10 2]);

to get the architecture you want. You don’t need to worry about the input layer size or output layer sizes. Those are set to ‘0’ and automatically set to the right size based on the inputs and outputs you provide to the network (net in the example) during training. In your case, you can reshape your 56×56 matrix into a 3136×1 vector:

x = reshape(x,3161,1);

So, following the above example, make sure your class/target labels are in t and your corresponding inputs in x and you’re good to go.

That being said, I would not use one of these networks to classify images. ConvNets are generally the way to go.

To split the input data (x and t) into training, validation and test sets and have the training function automatically take care of generalization ability like that, do this before training:

net.divideFcn = 'dividerand';
net.divideParam.trainRatio = 0.7;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.15;

Putting it together, we have:

[x,t] = simplefit_dataset;
net = feedforwardnet(10);
net.divideFcn = 'dividerand';
net.divideParam.trainRatio = 0.7;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.15;
net = train(net,x,t);
view(net)
y = net(x);
perf = perform(net,y,t)

4

solved How to use the custom neural network function in the MATLAB for images [closed]