Skip to content

Instantly share code, notes, and snippets.

@ugo-nama-kun
Last active September 15, 2021 07:37
Show Gist options
  • Save ugo-nama-kun/3d1141a5b62aea9ed3794d6cdb175d22 to your computer and use it in GitHub Desktop.
Save ugo-nama-kun/3d1141a5b62aea9ed3794d6cdb175d22 to your computer and use it in GitHub Desktop.
gym の render の画像を 正しくpytorch のモデルに打っ込むヤツ
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()
@ugo-nama-kun
Copy link
Author

You will get this
Figure_3

from this rgb image
Figure_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment