Comments (9)
First, you get criticc_gradient but didn't use it, I think it could be deleted here, https://github.com/dryang21/RL_IN_CSHARP/blob/9f70aeb8045d965fee09a3d76f956d3eb342149f/IPRL_debug.cs#L302C1-L303
Second, it will invoke stop_recording()
after invoke tape.gradient
, and then pop the _tapeSet
and the _tapeSet
will be empty. You call tape.gradient
twice in each for loop, for a total of six times, each using the same tape. So you have been using an empty _tapeSet after calling the first tape.gradient
, so it will cause an error. So you should use a new tape every time you call tape.gradient
. You can refer to this example:
If there still exsit any problems, please let me know.
from tensorflow.net.
You can use model.Apply(input)
from tensorflow.net.
Thanks for the quick replay, I really appreciate it. But the null gradient issue persists even after I change to model.Apply() . I was trying to perform a line-by-line translation of https://keras.io/examples/rl/actor_critic_cartpole/ the keras example from python to c#. All works smoothly except the tape.gradient(). I would greatly appreciate it if you could take the time to review my work and check if there are any errors or mistakes. The code is attached as follows:
https://github.com/dryang21/RL_IN_CSHARP/blob/main/IPRL_debug.cs
from tensorflow.net.
Is it possible to creat a branch and commit to GitHub? That will save us time to reproduce the issue.
from tensorflow.net.
Is it possible to creat a branch and commit to GitHub? That will save us time to reproduce the issue.
Thanks for the feedback.I have created a new repository and uploaded the .cs file. https://github.com/dryang21/RL_IN_CSHARP
from tensorflow.net.
First, you get criticc_gradient but didn't use it, I think it could be deleted here, https://github.com/dryang21/RL_IN_CSHARP/blob/9f70aeb8045d965fee09a3d76f956d3eb342149f/IPRL_debug.cs#L302C1-L303
Second, it will invoke
stop_recording()
after invoketape.gradient
, and then pop the_tapeSet
and the_tapeSet
will be empty. You calltape.gradient
twice in each for loop, for a total of six times, each using the same tape. So you have been using an empty _tapeSet after calling the firsttape.gradient
, so it will cause an error. So you should use a new tape every time you calltape.gradient
. You can refer to this example:If there still exsit any problems, please let me know.
Thanks for the suggestion. I have updated the code with: https://github.com/dryang21/RL_IN_CSHARP/blob/9f70aeb8045d965fee09a3d76f956d3eb342149f/IPRL_debug.cs
- initiate tape every epoch and call gradient only once for each tape
However, when I called gradient, the exception happened "stack empty". I tried to debug the process, I found that the count of the _tapeset was always zero even right after initialization, and the value of _tape showed "t_a._tape threw an exception of the type 'System.invalidOperationException' ".
Thank you for your assistance with this matter! I sincerely appreciate your time and help
The version setting:
1)visual studio 2019, c#7.3, .NET framework 4.7.2
(vs2022 could not be installed due to clinical computer restriction)
from tensorflow.net.
Hello, the code runs successfully after changing this line of code (https://github.com/dryang21/RL_IN_CSHARP/blob/1d48daa3952aa9b686d8751a5eb35a15bf2cfe70/IPRL_debug.cs#L263) to the following:
using (Tensorflow.Gradients.GradientTape t_a = tf.GradientTape(), t_b = tf.GradientTape())
Howerver, the loss didn't reduce and the value of reward didn't increase. I'm not familiar with RL so I'm not sure if this result of this code is correct.
from tensorflow.net.
Hello, the code runs successfully after changing this line of code (https://github.com/dryang21/RL_IN_CSHARP/blob/1d48daa3952aa9b686d8751a5eb35a15bf2cfe70/IPRL_debug.cs#L263) to the following:
using (Tensorflow.Gradients.GradientTape t_a = tf.GradientTape(), t_b = tf.GradientTape())
Howerver, the loss didn't reduce and the value of reward didn't increase. I'm not familiar with RL so I'm not sure if this result of this code is correct.
It works, thanks! Though it is a little weird that the gradient only works when using tensorflow.binding.
from tensorflow.net.
Close due to this problem has been solved.
from tensorflow.net.
Related Issues (20)
- Is is possible to implement a custom metric to support R^2 i.e. "Coefficient of determination" for a regression task?
- entry point not found HOT 5
- After installing TensorFlow.NET, HOT 2
- [BUG Report]: Model. predict() program crashes HOT 1
- Is bidirectional for LSTM even supported ? I am getting empty ( in C#/Tensorflow.NET 0 parameters) [Question]: HOT 4
- [Question]: Loading Python EfficientNetV2B0 model HOT 1
- [Question]: How can I create a model with multiple outputs?
- [Question]: System.NotImplementedException in Tensorflow.Checkpoint.CheckpointPosition._queue_slot_variables
- [BUG Report]: Model.fit verbose is always set to 1. HOT 2
- [BUG Report]: Normalization layer, must call .adapt after load and save
- Breadth-first traversal of augmented graph view causes collection modification exception
- tensorflow.keras is missing NuGet package README file
- [BUG Report]: Cannot find backend on Apple Silicon mac HOT 1
- [Question]: How to use regularizer ?
- Error when running model.fit after upgrade tensorflow.net to v0.150 HOT 1
- [BUG Report]: EarlyStopping Callback Stops Training Prematurely Regardless of Performance Improvement
- [Feature Request]: TimeDistributed and Dot
- [Performance Issue]: 125x performance difference between Python and TensorFlow.NET HOT 5
- [Question]: How to achieve glass breakage detection
- System.Collections.Generic.KeyNotFoundException: The given key '1' was not present in the dictionary. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow.net.