我尝试将 tf.keras 模型转换为 cntk,但这对我不起作用。
我使用了 MMdnn:mmconvert -sf keras -iw genre_predictor.krs -df cntk -om genre_predictor.dnn
但他输出了这条消息:
TypeError: 'InputLayer' object is not iterable
我也尝试将 keras 转换为 onnx,但我不知道如何运行具有负维度的 onnx 模型(在输入层 keras 模型具有 shape = (-1, 25000, 1),但 c# 中的 onnxruntime 可以不适用于 -1 维) 使用此代码:
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);
}
我有这个例外:
Unhandled exception. Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:InvalidArgument] Invalid Feed Input Name:first
Microsoft.CNTK 包也不能使用负维度。 使用此代码:
var device = DeviceDescriptor.CPUDevice;
Function.Load("genre_predictor.onnx", device, ModelFormat.ONNX);
我有这个例外:
About to throw exception 'ConvertAxisToCNTKCppApi cannot convert index < 0 to axis' Unhandled exception. System.ApplicationException: ConvertAxisToCNTKCppApi cannot convert index < 0 to axis
我不知道我可以用它做什么来通过 .net 运行 keras 模型二进制文件。请帮忙)
附言 我的 keras 模型:
(800, 25000, 1)
(None, 25000, 1)
Model: "GenrePredictor"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d (Conv1D) (None, 24951, 64) 3264
_________________________________________________________________
max_pooling1d (MaxPooling1D) (None, 2495, 64) 0
_________________________________________________________________
conv1d_1 (Conv1D) (None, 2446, 64) 204864
_________________________________________________________________
max_pooling1d_1 (MaxPooling1 (None, 244, 64) 0
_________________________________________________________________
flatten (Flatten) (None, 15616) 0
_________________________________________________________________
dense (Dense) (None, 1024) 15991808
_________________________________________________________________
dense_1 (Dense) (None, 512) 524800
_________________________________________________________________
dense_2 (Dense) (None, 256) 131328
_________________________________________________________________
dense_3 (Dense) (None, 10) 2570
=================================================================
Total params: 16,858,634
Trainable params: 16,858,634
Non-trainable params: 0