Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tf.image.resize() rather than cv2, and extend gym.core.Wrapper #118

Merged
merged 4 commits into from
Jul 23, 2019

Conversation

ageron
Copy link
Contributor

@ageron ageron commented May 24, 2019

TensorFlow has a tf.image.resize() method, why not use it instead of have a dependency on cv2?

Also, the AtariPreprocessing class does not have a close() method, and render() should have mode='human' by default, like other Gym environments. This can be solved easily by inheriting from the gym.core.Wrapper class, like all other wrappers.

@ageron
Copy link
Contributor Author

ageron commented May 24, 2019

Note: I timed tf.image.resize() and cv2.resize(), and it seems that cv2.resize() is about 30% faster than tf.image.resize(). Probably not a big deal since we're talking about a difference of about 100μs, but still worth mentioning. If we train a DQN for 50 million steps, this difference adds up to a total of about 2 hours on my computer, but since the GPU will probably be the bottleneck, rather than the CPU, it probably does not matter.
Perhaps one solution would be to check whether cv2 is installed or not, and use it if it is, otherwise use TensorFlow. However, although their outputs are very close, they are not perfectly identical, so it might be weird to have different results depending on which libraries are installed.

Copy link
Member

@sguada sguada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we separate that change from the rest? I think the change to gym.core.Wrapper is good.

tf_agents/environments/atari_preprocessing.py Outdated Show resolved Hide resolved
tf_agents/environments/atari_preprocessing.py Outdated Show resolved Hide resolved
@seungjaeryanlee
Copy link
Contributor

May I ask what the status of this PR is?

@tf-agents-copybara tf-agents-copybara merged commit 944a10f into tensorflow:master Jul 23, 2019
tf-agents-copybara pushed a commit that referenced this pull request Jul 23, 2019
PiperOrigin-RevId: 259620896
Change-Id: I20fc0537bad343d8e8cc6852d67159d008236235
@ageron ageron deleted the cv2_to_tf branch July 24, 2019 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants