.NET tensorflow problem - LSTM example
Budget: $15 – $25 USD
I am somewhat new to using Tensorflow and learn to use it from a C# application. I am trying to convert a simple LSTM Python example (https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/) that works very well on my machine in Python using the GPU. In my C# implementation, I have hard coded the input data to simplify the process. The data is identical in both the Python example and my code. However, when I try to build it in .NET (Visual Studio 2022), it crashes when the fit() method is encountered. First, the input_shape argument is not available in the LSTM constructor within .NET. So, the obvious thing to do would be to add an InputLayer instead. I have done this in the Python example code and it works fine. However, when I try to use the InputLayer in .NET, I get a completely different error than I am getting below. It seems like something rather screwy is going on that is not easily found in the documentation. I am absolutely baffled and have spent more time on this that virtually any other program error in my past. For the .NET application, I have the following 3 Nuget libraries currently added to the project...
scisharp.models.core (0.4.0)
scisharp.tensorflow.redist-windows-gpu (2.7.0)
Tensorflow.NET (0.70.1)
I am including files containing the slightly changed python code (that runs fine) from the online example as well as my C# program code for debugging. Again, here is the link to the online example (https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/).
Here is the error I get when the fit() method is encountered but I cannot get the InputLayer to work either.
2022-10-02 13:14:20.485908: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-10-02 13:14:20.892331: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 9432 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3080 Ti, pci bus id: 0000:0a:00.0, compute capability: 8.6
Unhandled exception. System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at Tensorflow.Keras.Engine.Sequential.track_nodes_created_by_last_call(ILayer layer, List`1 created_nodes)
at Tensorflow.Keras.Engine.Sequential._build_graph_network_for_inferred_shape(Shape input_shape, TF_DataType input_dtype)
at Tensorflow.Keras.Engine.Sequential.Call(Tensors inputs, Tensor state, Nullable`1 training)
at Tensorflow.Keras.Engine.Layer.Apply(Tensors inputs, Tensor state, Boolean training)
at Tensorflow.Keras.Engine.Model.train_step(Tensor x, Tensor y)
at Tensorflow.Keras.Engine.Model.train_step_function(OwnedIterator iterator)
at Tensorflow.Keras.Engine.Model.FitInternal(Int32 epochs, Int32 verbose)
at Tensorflow.Keras.Engine.Model.fit(NDArray x, NDArray y, Int32 batch_size, Int32 epochs, Int32 verbose, Single validation_split, Boolean shuffle, Int32 initial_epoch, Int32 max_queue_size, Int32 workers, Boolean use_multiprocessing)
at LSTM_Test.Program.Main(String[] args) in C:\Users\num1\source\repos\LSTM_Test\LSTM_Test\Program.cs:line 24
scisharp.models.core (0.4.0)
scisharp.tensorflow.redist-windows-gpu (2.7.0)
Tensorflow.NET (0.70.1)
I am including files containing the slightly changed python code (that runs fine) from the online example as well as my C# program code for debugging. Again, here is the link to the online example (https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/).
Here is the error I get when the fit() method is encountered but I cannot get the InputLayer to work either.
2022-10-02 13:14:20.485908: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-10-02 13:14:20.892331: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 9432 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3080 Ti, pci bus id: 0000:0a:00.0, compute capability: 8.6
Unhandled exception. System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at Tensorflow.Keras.Engine.Sequential.track_nodes_created_by_last_call(ILayer layer, List`1 created_nodes)
at Tensorflow.Keras.Engine.Sequential._build_graph_network_for_inferred_shape(Shape input_shape, TF_DataType input_dtype)
at Tensorflow.Keras.Engine.Sequential.Call(Tensors inputs, Tensor state, Nullable`1 training)
at Tensorflow.Keras.Engine.Layer.Apply(Tensors inputs, Tensor state, Boolean training)
at Tensorflow.Keras.Engine.Model.train_step(Tensor x, Tensor y)
at Tensorflow.Keras.Engine.Model.train_step_function(OwnedIterator iterator)
at Tensorflow.Keras.Engine.Model.FitInternal(Int32 epochs, Int32 verbose)
at Tensorflow.Keras.Engine.Model.fit(NDArray x, NDArray y, Int32 batch_size, Int32 epochs, Int32 verbose, Single validation_split, Boolean shuffle, Int32 initial_epoch, Int32 max_queue_size, Int32 workers, Boolean use_multiprocessing)
at LSTM_Test.Program.Main(String[] args) in C:\Users\num1\source\repos\LSTM_Test\LSTM_Test\Program.cs:line 24