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

Can't compute model output with NNSharp #3

Closed
Nadjib23 opened this issue Oct 29, 2017 · 3 comments
Closed

Can't compute model output with NNSharp #3

Nadjib23 opened this issue Oct 29, 2017 · 3 comments

Comments

@Nadjib23
Copy link

Nadjib23 commented Oct 29, 2017

Hi, i wanted to try NNSharp and i made a model with keras to classify iris flowers (classic) so the model takes 4 inputs and it gives an output of (0 or 1 or 2), it's a simple example juste to see how it works, here is my code :

       `double[] input = { 5.1, 3.5, 1.4, 0.2 };
        // Read the previously created json.
        var reader = new ReaderKerasModel("C:/Users/ben-n_000/Desktop/m.json");
        SequentialModel model = reader.GetSequentialExecutor();

        DataArray data = new DataArray(input.Length);
        for(int i=0;i< input.Length; i++)
        {
            data[i] = input[i];
        }
        Data2D k = (Data2D)data;

        IData output = model.ExecuteNetwork(k);

        Data2D ou = (Data2D)output;

        //output.
        Console.WriteLine(ou. !!!!);`

Here i can't find a methode to display the output and i can't find the right documentation !!!

@adamtiger
Copy link
Owner

Hi! Thank you for your question!

Currently there is no function for creating a string representation for Data2D. So you should write the elements for the screen one by one. But I do not recommend this. Instead create another Data2D tensor with the expected results and compare it to the output of your network. To understand the shape of the output just use the NNSharp docs. There, under Keras you can find the implemented layers and it will tell you what is the output. So just look the documentation for the last layer of your network.

Let me know if your test is successful or not!

@Nadjib23
Copy link
Author

Nadjib23 commented Nov 1, 2017

Hi thank you for you quick answer, i find a way to get a string representation of the different layers of the keras model, that show the inputs and outputs for all the layers including the last layer (output)

    `// String representation of the keras model 

       SequentialModelData d = (SequentialModelData)model.GetSummary();

        Console.WriteLine(d.GetStringRepresentation());
      `

since i can see the model architecture, and know the output dimension (1 output for my case), i can print out the output (at index 0 in the channels parameter) because i have only one output

    ` IData output = model.ExecuteNetwork(k);

     Data2D ou = (Data2D)output;

    //output : 3rd parameter 0 is the channels parameter

    Console.WriteLine(ou[0, 0, 0, 0]);

`

@adamtiger
Copy link
Owner

Yes, that is good solution as well.

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

No branches or pull requests

2 participants