Comments (4)
I resolved the nans :) So the issue was actually in rollout
and compute_rtgs
; you had some pieces of code on the wrong indent, which were early terminating the two functions before they had a chance to finish their loops.
Specifically in rollout
, I shifted:
# Collect episodic length and Rewards
batch_lens.append(ep_t + 1)
batch_rews.append(ep_rews)
one indent left, and
#Reshape data as tensors
batch_obs = torch.tensor(batch_obs, dtype=torch.float)
batch_acts = torch.tensor(batch_acts, dtype=torch.float)
batch_log_probs = torch.tensor(batch_log_probs, dtype=torch.float)
# ALG STEP 4
batch_rtgs = self.compute_rtgs(batch_rews)
print(f'Batch rewards before logger======={batch_rews}')
# Log the episodic returns and episodic lengths in this batch.
self.logger['batch_rews'] = batch_rews
self.logger['batch_lens'] = batch_lens
# Return the batch data
return batch_obs, batch_acts, batch_log_probs, batch_rtgs, batch_lens
two indents left.
In compute_rtgs
, I shifted:
#Convert the reward-to-go into a tensor
batch_rtgs = torch.tensor(batch_rtgs, dtype=torch.float)
return batch_rtgs
one indent left.
Here's ppo.py with the fixes: ppo.py.zip. Let me know if there's anything else I can help with :) Otherwise, marking this issue as closed.
from ppo-for-beginners.
Works :) Thanks a lot..
from ppo-for-beginners.
Hi Briti!
I just tried your block of code with the repo code, and it works out for me (had to change model = PPO(env=env, **hyperparameters)
to model = PPO(policy_class=FeedForwardNN, env=env, **hyperparameters)
though).
Output:
Model information ====== <ppo.PPO object at 0x7fa61287c358>
Learning... Running 200 timesteps per episode, 2048 timesteps per batch for a total of 1000000 timesteps
-------------------- Iteration #1 --------------------
Average Episodic Length: 200.0
Average Episodic Return: -1358.09
Average Loss: -0.00129
Timesteps So Far: 2200
------------------------------------------------------
-------------------- Iteration #2 --------------------
Average Episodic Length: 200.0
Average Episodic Return: -1172.53
Average Loss: -0.001
Timesteps So Far: 4400
------------------------------------------------------
^C
I suspect something in your ppo.py
implementation is incorrect; would you mind sending me your ppo.py
code?
from ppo-for-beginners.
Hi Eric,
Thank you for your reply. Attaching my
ppo.zip
ppo.py. I suspect there is something wrong with the get_action() method. Kindly help.
from ppo-for-beginners.
Related Issues (8)
- the python version of this repo? HOT 1
- ImportError: libboost_filesystem.so.1.65.1 in Collab HOT 1
- How to fix: Broken with latest gym pip package HOT 1
- PPO gets stuck in custom environment HOT 6
- covariance matrix HOT 1
- Using for custom environment with different actions HOT 1
- why critic's loss is mean squared error of the predicted values with rewards-to-go. 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 ppo-for-beginners.