Open aench2023 opened 6 years ago
Have you tried it? A few examples here: https://github.com/Microsoft/CNTK/tree/master/Examples/Evaluation
I tried the example, I am getting the following error:
Additional information: Values for 1 required arguments 'Input('input_1', [3 x ? x ?], [#])', that the requested output(s) 'Output('Softmax22978_Output_0', [39], [#])' depend on, have not been provided.
Could you provide us a small repro for this? Thanks!
I believe this is the same question as in issue #2250. I would like to know the correct code in order to achieve these steps:
1) Save a trained Keras model in such a way that it can be opened in a C# application. 2) Load model into C# application (with appropriate NuGet file installed) 3) Evaluate model with real-time data
Note: in my case I have a quite simple LSTM model.
As Rita mentioned, I was trying to do the same, I have an inceptionv3 model created using keras, I saved it as CNTK model and I am trying to read it into c#
I am using the code below:
Console.WriteLine("\n===== Evaluate single image =====");
string modelFilePath = "inception_cntk";
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
Function modelFunc = Function.Load(modelFilePath, device);
Variable inputVar = modelFunc.Arguments.Single();
NDShape inputShape = inputVar.Shape;
int imageWidth = inputShape[0];
int imageHeight = inputShape[1];
int imageChannels = inputShape[2];
Variable outputVar = modelFunc.Output;
var inputDataMap = new Dictionary<Variable, Value>();
var outputDataMap = new Dictionary<Variable, Value>();
string sampleImage = "00000.png";
ThrowIfFileNotExist(sampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", sampleImage));
Bitmap bmp = new Bitmap(Bitmap.FromFile(sampleImage));
var resized = bmp.Resize((int)imageWidth, (int)imageHeight, true);
List<float> resizedCHW = resized.ParallelExtractCHW();
Value inputVal = Value.CreateBatch(inputVar.Shape, resizedCHW, device);
inputDataMap.Add(inputVar, inputVal);
outputDataMap.Add(outputVar, null);
modelFunc.Evaluate(inputDataMap, outputDataMap, device);
var outputVal = outputDataMap[outputVar];
var outputData = outputVal.GetDenseData<float>(outputVar);
PrintOutput(inputVar.Shape.TotalSize, outputData);
To convert the model to CNTK model I used the following code:
import cntk as C from keras.models import load_model keras_model = load_model('inceptionv3-ft.model') C.combine(keras_model.outputs).save('inception_cntk')
@akegramener. This does not make sense. There is only one argument as input. Is there any way you can share me the model. Or point me to the source so I can repro? Thanks
Below is the link to the model https://drive.google.com/file/d/0Bwfks2dAvyXcTW15TmVER0FPY1U/view
Also this is the link to the code https://github.com/akegramener/Model-Evaluation-CSharp
Thanks!
@akegramener Sorry for the delay. It looks like a bug of CNTK to handle free and inferred dimensions. The attached model has input with dimensions being -1 (inferred dim). However current CNTK can only handle input with free dimensions (-3). For example, this code works: x = C.input((-3,-3, 2)) data = np.random.random((10, 10, 2)) y = x + 1 y.eval({x:[data]})
But this code does not: x = C.input((-1,-1, 2)) data = np.random.random((10, 10, 2)) y = x + 1 y.eval({x:[data]})
Note that the attached model also has input dim being -1. I mark this issue as a bug and track with it. Thanks.
Hi,
We have a model that is trained using Keras and CNTK, I would like to evaluate the model using C#, how do I go about doing that? Also the trained model is inception_v3