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

save_to_gif argument in Trainer #291

Open
Sharad24 opened this issue Aug 30, 2020 · 3 comments
Open

save_to_gif argument in Trainer #291

Sharad24 opened this issue Aug 30, 2020 · 3 comments
Labels

Comments

@Sharad24
Copy link
Member

Sharad24 commented Aug 30, 2020

Save a GIF file based on this argument in trainer.

To-do:

  1. Check tensorboard saving in video
@sampreet-arthi
Copy link
Member

This might be useful here.

@AdityaKapoor74
Copy link
Contributor

An example code snippet for this issue:

# ignore this
from simple_spread_test import make_env
from maa2c import MAA2C

import imageio
import numpy as np
import os
import torch


if __name__ == '__main__':
	env = make_env(scenario_name="simple_spread")
	ma_controller = MAA2C(env ,gif = True)




	# Number of images to capture
	n_images = 10000

	images = []

	# init a new episode
	obs = env.reset()
	# init the img var with the starting state of the env
	img = env.render(mode='rgb_array')[0]

	for i in range(n_images):
	  # At each step, append an image to list
	  images.append(img)

	  # Advance a step and render a new image
	  with torch.no_grad():
	    action = ma_controller.get_actions(obs)
	  obs, _, _ ,_ = env.step(action)
	  img = env.render(mode='rgb_array')[0]


	 imageio.mimwrite('./simple_spread.gif',
	                 [np.array(img) for i, img in enumerate(images) if i%2 == 0],
	                 fps=50)

@Sharad24 Sharad24 added the good first issue Good for newcomers label Aug 30, 2020
@github-actions
Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants