question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

results_plotter error: "tuple indices must be integers or slices, not str"

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
YangRui2015commented, Apr 23, 2020

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)

0reactions
ztz695183179commented, Jun 5, 2020

same problem, request a perfect solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: tuple indices must be integers or slices, not str
The Python TypeError: tuple indices must be integers or slices, not str occurs when we use a string instead of an integer to...
Read more >
Python Error: tuple indices must be integers or slices, not str
When I am running I run into an error that says tuple indices must be integers or slices, not str. When I print...
Read more >
TypeError: tuple indices must be integers, not str - Codecademy
TypeError: tuple indices must be integers, not str ... they are considered tuples, tuples are like lists except immutable (can't be changed once...
Read more >
TypeError: tuple indices must be integers or slices, not str ...
python tutorial: #codefix #python #python_tutorialsTypeError: tuple indices must be integers or slices, not str : In this video i have shared ...
Read more >
TypeError: tuple indices must be integers or slices, not str ...
The typeerror: tuple indices must be integers or slices, not str error comes when you can't get row information using row["pool_number"].
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found