Last active
September 15, 2021 07:37
-
-
Save ugo-nama-kun/3d1141a5b62aea9ed3794d6cdb175d22 to your computer and use it in GitHub Desktop.
gym の render の画像を 正しくpytorch のモデルに打っ込むヤツ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Assuming some environment that render image... | |
im = env.render(mode="rgb_array", | |
height=84, | |
width=84, | |
camera_id=0) / 255. | |
im = torch.tensor(im.astype(np.float32)) | |
im = im.view(-1, 84, 84, 3).permute(0, 3, 1, 2) | |
im = im.detach().numpy() | |
# visualization | |
im = np.hstack([im[0, 0], | |
im[0, 1], | |
im[0, 2]]) | |
plt.figure() | |
plt.imshow(im, cmap="gray") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will get this

from this rgb image
