Comments (7)
Hi Eric,
Note that you are using a tf_environment
. The way your code is structured you are generating Tensorflow Ops, but not evaluating them which is causing the increase in memory usage.
You'll want to change the later segment of your code to be:
tf_py_env = MyEnv()
tf_env = tf_py_environment.TFPyEnvironment(tf_py_env)
action = tf.constant([0.0])
reset_op = tf_env.reset()
step_op = tf_env.step(action)
i = 0
with tf.Session() as sess:
while True:
if i % 10000 == 0:
print(i)
time_step = sess.run(reset_op)
time_step = sess.run(step_op)
i += 1
from agents.
Thank you so much for your help! It completely makes sense.
I think I was just following agents/tf_agents/colabs/environments_tutorial.ipynb
without thinking too much about it and also overlooked tf.enable_eager_execution()
.
Thanks again.
from agents.
@oars After running your code, I actually got an error:
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
Do you know how I can fix this?
Also, as I mentioned above, when I ran the code tf_agents/agents/dqn/examples/train_eval_atari.py
with no modification, the memory usage still fluctuated between 40% to 80+%, in which case my computer also becomes slower. Is that to be expected?
Thanks!
from agents.
Can you try updating tf-agents and trying again? I can't reproduce your error. For reference I just re-ran with this code:
import tensorflow as tf
from tf_agents.environments import tf_py_environment, py_environment
from tf_agents.specs import array_spec
from tf_agents.environments import time_step as ts
import numpy as np
img_size = 5000
class MyEnv(py_environment.Base):
def __init__(self):
self._action_spec = array_spec.BoundedArraySpec(shape=(), dtype=np.float32)
self._observation_spec = array_spec.BoundedArraySpec(shape=(img_size, img_size, 3), dtype=np.float32)
def action_spec(self):
return self._action_spec
def observation_spec(self):
return self._observation_spec
def _reset(self):
return ts.restart(np.zeros(shape=(img_size, img_size, 3), dtype=np.float32))
def _step(self, action):
return ts.transition(np.zeros(shape=(img_size, img_size, 3), dtype=np.float32), reward=0.0, discount=1.0)
tf_py_env = MyEnv()
tf_env = tf_py_environment.TFPyEnvironment(tf_py_env)
action = tf.constant([0.0])
reset_op = tf_env.reset()
step_op = tf_env.step(action)
i = 0
with tf.Session() as sess:
while True:
if i % 100 == 0:
print(i)
time_step = sess.run(reset_op)
time_step = sess.run(step_op)
i += 1
Regarding the memory fluctuations I wouldn't expect that to happen either. Note that your image is fairly large ~280MB as raw float32 so if there are a couple of internal instances of it memory usage will be large.
from agents.
It works!
I used tf.enable_eager_execution()
before and it didn't work.
Sorry I should have spent more time understanding tf eager mode and this error should be obvious. Thanks a lot.
from agents.
@oars How to deal with it in tf 2.0 without tf.Session ?
from agents.
How to deal with what? There are examples using environments in 2.0. Please look at the colabs.
from agents.
Related Issues (20)
- Add support for gym_kwargs in suite_atari HOT 1
- Q-Network wrong output spec HOT 1
- remove tensorflow warning around tf.function on per_field_where
- Per-Arm Features guide/tutorial not in site table of contents HOT 1
- How to run Code on Windows
- Parallelization of this "CartPole v0" standard environment failed
- DQN Tutorial.ipynb not working HOT 2
- Feature Request: expose a target_update method for DQNAgent
- Problem with AverageReturnMetric
- How to convert keras Model to DDQN QNetwork?
- [Fix this ASAP] TypeError : 'AtariEnv.render() takes 1 positional argument but 2 were given' and some environments can't be rendered HOT 1
- Inference MAB HOT 1
- No module named 'tensorflow.python.training.tracking HOT 1
- Multi arm Multi play Setting
- got an unexpected keyword argument 'kwargs' when create_variables and unable to copy
- PPOAgent + MaskSplitterNetwork normalizes Mask when observation normalization is turned on.
- WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).agent._optimizer._variables.1
- PolicySavedModelTrigger has no sweeping ability.
- Compatibility with gymnasium environments
- Type error in PolicySaver.save() 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 agents.