Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
17.12k stars 4.15k forks source link

Persistant Issue with UnityEnvironment() for Custom Training Algorithms #4545

Closed justkittenaround closed 2 years ago

justkittenaround commented 4 years ago

Describe the bug Cannot load custom environment with ml-agents-envs API via UnityEnvironment(). I would like to load my custom environment I built in Unity editor and access it with the ml-agents API so I can train it with my custom learning algorithm in python.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md and follow download instructions (not advanced, just regular).
  2. Go to https://github.com/Unity-Technologies/ml-agents/blob/release_7_docs/docs/Learning-Environment-Executable.md and follow the instructions until "Training the environment'. Note 'Display Resolution Dialog' does not exist but is recommended on the docs.
  3. See error in terminal.

Console logs / stack traces >>>import mlagents >>>from mlagents_envs.environment import UnityEnvironment as UE

>>>env = UE(file_name = '3DBall_build') Found path: /home/whale/Unity/ml-agents-release_7/3DBall_build.x86_64

>>>env <mlagents_envs.environment.UnityEnvironment object at 0x7fbc4a103eb8>

>>>list(env.behavior_specs) []

Screenshots see video under reproduce section above

Environment (please complete the following information): I have tried with multiple Unity environments, both my own that I built and examples from the latest release (7) in ml-agents repository. I've also tried uninstalling everything and reinstalling. I've tried with Anaconda and just on local.

andrewcoh commented 4 years ago

Hi @justkittenaround

Can you try calling env.reset() and then checking this list? Please see my screenshot:

Screen Shot 2020-10-09 at 10 13 18 AM
justkittenaround commented 4 years ago

Hi @andrewcoh, thanks for looking into it. env.reset() did not resolve the error. Bellow is the results. Screenshot from 2020-10-09 10-39-41

andrewcoh commented 4 years ago

Ah, I see the issue occurs when actually trying to load the executable i.e. the 'is not responding' error. It could be a resolution mismatch.

Can you try setting Fullscreen Mode to 'Windowed' in the player settings when you create your build?

justkittenaround commented 4 years ago

@andrewcoh I have it set to windowed. Here is a screenshot of my player settings. I just want to be sure you know I am working with Ubuntu here. Could it be a Ubuntu issue? I can't get it to work with any scene. Screenshot from 2020-10-13 13-03-26

andrewcoh commented 4 years ago

Yep, I'm aware you're using Ubuntu.

I should've asked this earlier (but I think I saw your forum post mentioning this): are you able to get this to run using mlagents-learn and the --env command?

justkittenaround commented 4 years ago

@andrewcoh thanks for taking that into account. I did originally post on the forum because I thought it might be something I was doing wrong.

I am able to get it training using the mlagents-learn command. The problem is that I want to use my own training algorithm instead of the built in ones. I was under the impression that we can't do that with mlagents-learn, we need to use the mlagents-envs. Is that correct?

andrewcoh commented 4 years ago

Yes, you have that correct and it's not obvious to me just yet that you're doing anything wrong. I'll do some troubleshooting and get back to you.

justkittenaround commented 4 years ago

@andrewcoh I seem to have found a solution. First, the build needs to be in the project folder where I created the scene in unity editor. Secondly, I have to build the executable in debugging mode only. Third, when the environment opens after I call UnityEnvironment with the file name, I have to click "wait" when it crashes instead of "force close".

Thanks for looking into it! Seems a little buggy but glad I got a solution so I can start using the awesome API.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity in the last 28 days. It will be closed in the next 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not had activity in the last 42 days. If this issue is still valid, please ping a maintainer. Thank you for your contributions.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.