skjb / pysc2-tutorial

Tutorials for building a PySC2 bot
https://medium.com/@skjb/building-a-basic-pysc2-agent-b109cde1477c
MIT License
287 stars 85 forks source link

TypeError: reduction operation 'argmax' not allowed for this dtype #6

Closed Lukasas closed 6 years ago

Lukasas commented 6 years ago

I'm trying to run the script but I'm getting this error.

I1208 14:55:06.231405 6620 sc2_env.py:200] Environment is ready. I1208 14:55:06.232910 6620 sc2_env.py:240] Starting episode: 1 Took 0.063 seconds for 1 steps: 15.957 fps I1208 14:55:06.295577 6620 sc2_env.py:327] Environment Close I1208 14:55:06.295577 6620 sc2_env.py:342] Traceback (most recent call last): File "C:\Programy\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "C:\Programy\Python\Python36\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Programy\Python\Python36\lib\site-packages\pysc2\bin\agent.py", line 112, in app.run(main) File "C:\Programy\Python\Python36\lib\site-packages\absl\app.py", line 274, in run _run_main(main, argv) File "C:\Programy\Python\Python36\lib\site-packages\absl\app.py", line 238, in _run_main sys.exit(main(argv)) File "C:\Programy\Python\Python36\lib\site-packages\pysc2\bin\agent.py", line 98, in main run_thread(agent_cls, FLAGS.map, FLAGS.render) File "C:\Programy\Python\Python36\lib\site-packages\pysc2\bin\agent.py", line 77, in run_thread run_loop.run_loop([agent], env, FLAGS.max_agent_steps) File "C:\Programy\Python\Python36\lib\site-packages\pysc2\env\run_loop.py", line 41, in run_loop for agent, timestep in zip(agents, timesteps)] File "C:\Programy\Python\Python36\lib\site-packages\pysc2\env\run_loop.py", line 41, in for agent, timestep in zip(agents, timesteps)] File "I:\Starcraft 2 Projects\SmartBot\SMBot.py", line 177, in step rl_action = self.qlearn.choose_action(str(current_state)) File "I:\Starcraft 2 Projects\SmartBot\SMBot.py", line 80, in choose_action action = state_action.idxmax() File "C:\Programy\Python\Python36\lib\site-packages\pandas\core\series.py", line 1357, in idxmax i = nanops.nanargmax(_values_from_object(self), skipna=skipna) File "C:\Programy\Python\Python36\lib\site-packages\pandas\core\nanops.py", line 74, in _f raise TypeError(msg.format(name=f.name.replace('nan', ''))) TypeError: reduction operation 'argmax' not allowed for this dtype I1208 14:55:06.309614 6620 sc2_env.py:327] Environment Close I1208 14:55:06.309614 6620 sc2_env.py:342] I1208 14:55:06.310115 6620 sc2_env.py:327] Environment Close I1208 14:55:06.310115 6620 sc2_env.py:342] W1208 14:55:09.418379 6620 sc_process.py:183] Killing the process. I1208 14:55:09.544715 6620 sc_process.py:166] Shutdown with return code: 1

nanxintin commented 6 years ago

@Lukasas I change the version of pandas to 0.20.3 and run the code successfully.

skjb commented 6 years ago

@Lukasas Change action = state_action.argmax() to action = state_action.idxmax()

Lukasas commented 6 years ago

But, should it be state_action.idxmax() or state_action.values.argmax()? Whats the difference?

skjb commented 6 years ago

I copied the original code from here https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow/blob/master/contents/2_Q_Learning_maze/RL_brain.py and they updated it to state_action.idxmax() which seems to work for me

Lukasas commented 6 years ago

I updated my pandas version to 0.21.1 and the only thing that works is state_action.values.argmax() but it behaves differently from the state_action.idxmax() in previous version.

skjb commented 6 years ago

Maybe this: https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow/commit/d69b93638a30d770cadb7247a7392d891a1ded18#diff-4e022d49f9536011dbf7b3c2cdc45b6f

Lukasas commented 6 years ago

Yes, that works, but I still wonder whats the difference between these two. Their documentation says it's basicly same thing, but it gives different values.

Lukasas commented 6 years ago

Well, I can say it works now, The bot wins or ties almost every game. But I still need to do some research. Thank you anyway

nanxintin commented 6 years ago

@Lukasas @skjb I have trained the smart agent and attack agent for over 800 episodes, but the win rates are still very low. What is the training results of your agents?

Lukasas commented 6 years ago

Mine has like 30% win, 20% ties and 50% loses

nanxintin commented 6 years ago

@Lukasas how many episodes to train the agent ?

Lukasas commented 6 years ago

Well, it starts to spam marines from the beggining and then just send it to Attack, and its improving the point of Attack, usually it wins somewhere between 3th and 9th episode

nanxintin commented 6 years ago

I set the bot_race to T and run "python -m pysc2.bin.agent --map Simple64 --agent attack_agent.AttackAgent --agent_race T --bot_race T --max_agent_steps 0". Do you specify the bot race?

Lukasas commented 6 years ago

No, I let it to train on random bot.

nanxintin commented 6 years ago

I still fail to train the attack agent and smart agent after 40 episodes, losing all the games. The agent just send marines to attack but they will be destroyed soon. It is strange.

Lukasas commented 6 years ago

I've set to build more barracks so the smart bot can build marines quicker. Then he is just overwhelming enemy bot with it

CaptainpingchuanDing commented 6 years ago

hi, did you fix this bugs? Can you run it correctly?