[BUG Report]: 使用Lstm同样的代码,再python正常运行,但是使用.net报错
Description
python代码: import numpy as np import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers
inputs = tf.random.normal([32, 10, 8]) lstm = tf.keras.layers.LSTM(4) output = lstm(inputs) print(output.shape) #(32, 4) lstm = tf.keras.layers.LSTM(4, return_sequences=True, return_state=True) whole_seq_output, final_memory_state, final_carry_state = lstm(inputs) print(whole_seq_output.shape) #(32, 10, 4) print(final_memory_state.shape) #(32, 4) print(final_carry_state.shape) #(32, 4)
C#代码: var inputs = tf.random.normal(new Shape(32, 10, 8)); var lstm = new Tensorflow.Keras.Layers.LSTM(new LSTMArgs() { Units = 4, //InputShape = new Shape(10,8) }); var y = lstm.Apply(inputs);//在这个位置报错,提示索引超出范围 print(y.shape);
Reproduction Steps
No response
Known Workarounds
无解决办法 No response
Configuration and Other Information
No response
请检查如下事项:
- Python的Tensorflow版本,Py版本,C#版本问题
- 测试输出InputShape的维度(显示输出),并对应查看Python的维度。
剩下的你应该可以解决了
解决了,要改成: model.add(new Tensorflow.Keras.Layers.LSTM(new LSTMArgs() { Units = 4, RecurrentActivation = tf.keras.activations.Sigmoid, Activation = tf.keras.activations.Tanh, Name = "layer2", //InputShape = new Shape(10, 10), //ReturnState = false, //ReturnSequences = true, })); 加了 RecurrentActivation = tf.keras.activations.Sigmoid, Activation = tf.keras.activations.Tanh, 因为Python默认帮填了这几个参数,但是C#的版本没有,所以导致报错