NeuralNetwork.NET icon indicating copy to clipboard operation
NeuralNetwork.NET copied to clipboard

Compute neural network

Open quequiere opened this issue 4 years ago • 2 comments

Hi! Sorry but I still don't understand how to compute neural network when the training is over.

Should I use: network.ExtractDeepFeatures(input); ?

quequiere avatar Jan 09 '20 20:01 quequiere

Hi, thank you for using my lib! 😊 You can get the outputs of the trained network for a given input tensor by calling one of the Forward methods of the network. That ExtractDeepFeatures method is meant to be used to extract features for one of the hidden layers of the network in case you want to do some transfer learning.

In your case you can just use Forward and it'll give you the output from your trained network 👍 Let me know if that works for you!

Sergio0694 avatar Jan 09 '20 21:01 Sergio0694

Thank you very mush Sergio for your quick answer =) I trying multiple libs for neural network with GPU for a personnal project. And your library could help me.

I'm trying to solve a simple problem for now to understand how your lib work.

` INeuralNetwork network = NetworkManager.NewSequential(TensorInfo.Linear(1), NetworkLayers.FullyConnected(20,ActivationType.ReLU), NetworkLayers.FullyConnected(20,ActivationType.ReLU), NetworkLayers.Softmax(2) );

        List<(float[] x, float[] u)> data = new List<(float[] x, float[] u)>();

        data.Add((new float[] { 1}, new float[] {1,0}));
        data.Add((new float[] { 2}, new float[] {0,1}));
        data.Add((new float[] { 3}, new float[] {1,0}));
        data.Add((new float[] { 4}, new float[] {0,1}));
        data.Add((new float[] { 5}, new float[] {1,0}));
        data.Add((new float[] { 6}, new float[] {0,1}));
        data.Add((new float[] { 7}, new float[] {1,0}));
        data.Add((new float[] { 8}, new float[] {0,1}));
        data.Add((new float[] { 9}, new float[] {1,0}));
        data.Add((new float[] { 10}, new float[] {0,1}));


       ITestDataset test = DatasetLoader.Test(data, p => {

            Console.WriteLine($"Epoch {p.Iteration}, cost: {p.Result.Cost}, accuracy: {p.Result.Accuracy} "); // Progress report

        });



        ITrainingDataset dataset = DatasetLoader.Training(data, data.Count);

        TrainingSessionResult result = NetworkManager.TrainNetwork(
            network,                                // The network instance to train
            dataset,                                // The ITrainingDataset instance   
            TrainingAlgorithms.AdaDelta(),          // The training algorithm to use
            2000,                                     // The expected number of training epochs to run
            0.5f,                                   // Dropout probability
            null,                               // Optional training epoch progress callback
            null,                                   // Optional callback to monitor the training dataset accuracy
            null,                                   // Optional validation dataset
            test,                                   // Test dataset
            default);



        var input = new float[] { 5 };
        var input2 = new float[] { 10 };

        var result1 = network.Forward(input);
        var result2 = network.Forward(input2);

        Console.WriteLine(result1[0]+" VS "+result1[1]); // Should be 1 VS 0 
        Console.WriteLine(result2[0]+" VS "+ result2[1]);  // Should be 0 VS 1`

This neural network should say me if a number is an even number or not. But when I train then network the accuracy is 60 never more :S

Could you explain me my error if you have the time ^^ ?

quequiere avatar Jan 10 '20 05:01 quequiere