Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute neural network #95

Open
quequiere opened this issue Jan 9, 2020 · 2 comments
Open

Compute neural network #95

quequiere opened this issue Jan 9, 2020 · 2 comments
Labels

Comments

@quequiere
Copy link

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

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

@Sergio0694
Copy link
Owner

Sergio0694 commented Jan 9, 2020

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!

@quequiere
Copy link
Author

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 ^^ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants