genrl icon indicating copy to clipboard operation
genrl copied to clipboard

save_to_gif argument in Trainer

Open Sharad24 opened this issue 5 years ago • 3 comments

Save a GIF file based on this argument in trainer.

To-do:

  1. Check tensorboard saving in video

Sharad24 avatar Aug 30 '20 11:08 Sharad24

This might be useful here.

sampreet-arthi avatar Aug 30 '20 11:08 sampreet-arthi

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)

AdityaKapoor74 avatar Aug 30 '20 11:08 AdityaKapoor74

Stale issue message

github-actions[bot] avatar Oct 30 '20 00:10 github-actions[bot]