microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.49k stars 4.3k forks source link

Keras, cntk and onnx #3851

Closed replikeit closed 3 years ago

replikeit commented 3 years ago

I tried convert tf.keras model to cntk, but this does not work for me. I used MMdnn: mmconvert -sf keras -iw genre_predictor.krs -df cntk -om genre_predictor.dnn But he outputs this message: TypeError: 'InputLayer' object is not iterable

I also try to convert keras to onnx, but i have no idea how i can run onnx model with negative dimension(at the input layer keras model have shape = (-1, 25000, 1), but onnxruntime in c# can't work with -1 dimension) With this code:

         var sess = new InferenceSession("genre_predictor.onnx");
         var inputsDimensions = sess.InputMetadata.Values.First(); // int {-1, 25000, 1}
         Tensor<float> t1 = new DenseTensor<float>(new float[25000], new int[] {1, 25000, 1});
         var inputs = new List<NamedOnnxValue>()
         {
             NamedOnnxValue.CreateFromTensor<float>("first", t1)
         };
         sess.Run(inputs);
         using (var outputs = sess.Run(inputs))
         {
             Console.WriteLine(outputs);
         }

I have this exception: Unhandled exception. Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:InvalidArgument] Invalid Feed Input Name:first

Microsoft.CNTK package also can't work with negative dimension. With this code:

var device = DeviceDescriptor.CPUDevice;
Function.Load("genre_predictor.onnx", device, ModelFormat.ONNX);

I have this exception: About to throw exception 'ConvertAxisToCNTKCppApi cannot convert index < 0 to axis' Unhandled exception. System.ApplicationException: ConvertAxisToCNTKCppApi cannot convert index < 0 to axis

I have no idea what I can do with this to run the keras model binary via .net. Pls help)