baselines
baselines copied to clipboard
results_plotter error: "tuple indices must be integers or slices, not str"
Hi there!
I tried to use the results_plotter.py code to plot my results of training, however when I run it either on jupyter or on terminal it gives me the following error massege (this is on jupyter-notebook):
-----------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-3f0abc02953f> in <module>()
----> 1 plot_results("~/logs/cartpole-ppo-log")
~/MachineLearning/DRL/OpenAI/baselines/0.Mine/baselines/results_plotter.py in plot_results(dirs, num_timesteps, xaxis, yaxis, title, split_fn)
69 def plot_results(dirs, num_timesteps=10e6, xaxis=X_TIMESTEPS, yaxis=Y_REWARD, title='', split_fn=split_by_task):
70 results = plot_util.load_results(dirs)
---> 71 plot_util.plot_results(results, xy_fn=lambda r: ts2xy(r['monitor'], xaxis, yaxis), split_fn=split_fn, average_group=True, resample=int(1e6))
72
73 # Example usage in jupyter-notebook
~/MachineLearning/DRL/OpenAI/baselines/0.Mine/baselines/common/plot_util.py in plot_results(allresults, xy_fn, split_fn, group_fn, average_group, shaded_std, shaded_err, figsize, legend_outside, resample, smooth_step)
297 sk2r = defaultdict(list) # splitkey2results
298 for result in allresults:
--> 299 splitkey = split_fn(result)
300 sk2r[splitkey].append(result)
301 assert len(sk2r) > 0
~/MachineLearning/DRL/OpenAI/baselines/0.Mine/baselines/results_plotter.py in split_by_task(taskpath)
65
66 def split_by_task(taskpath):
---> 67 return taskpath['dirname'].split('/')[-1].split('-')[0]
68
69 def plot_results(dirs, num_timesteps=10e6, xaxis=X_TIMESTEPS, yaxis=Y_REWARD, title='', split_fn=split_by_task):
TypeError: tuple indices must be integers or slices, not str
What is the problem?!
Best regards.
Same problem.
the same
I get the same problem because the taskpath is not a dict, using the follow codes to fix this:
if type(taskpath) == dict:
return taskpath['dirname'].split('/')[-1].split('-')[0] `
else:
return taskpath.dirname.split('/')[-1].split('-')[0]
It's the same in plot_results function:
xy_fn=lambda r: ts2xy(r.monitor, xaxis, yaxis)
same problem
same problem, request a perfect solution