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.19k stars 4.16k forks source link

Small window and full speed using env.step() #3021

Closed valentinmace closed 4 years ago

valentinmace commented 4 years ago

Hi, I'm new to mlagents

I have a python script interacting with 3DBall environment

Everything seems to work, I can launch the game and get observations, provide actions etc.

However when I run the game, it is always in a small window and the game is going at full speed. My code looks like:

env = UnityEnvironment(file_name=env_name, worker_id=0, seed=1)

env_info = env.reset(train_mode=False, config=None)
for i in range(400):
    env.step(vector_action=some_random_action)

First note: When I only instantiate the environment with env = UnityEnvironment(...) and do nothing else, the game is in full window, going at normal speed

Second note: My goal is to train my own neural network (which I implemented myself so there is no TF or Pytorch) with my own algorithm. When the training is over I would like to visualize my NN playing in a full size window at normal speed

Thanks in advance for your answer, sorry if I the solution was in the doc and I missed it

chriselion commented 4 years ago

Hi @valentinmace, I think the settings you're looking for are available in the Academy (in Unity): https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Learning-Environment-Design-Academy.md#academy-properties By default, training happens at 80x80 and 100x timescale, and inference is 1280x720 and normal timescale, but you can adjust them in the Academy.

Just a note that the interface for this will change in the next release; these parameters will be set on the python commandline or as arguments to UnityEnvironment.

valentinmace commented 4 years ago

Thanks for your quick answer @chriselion

You are right, I can change these parameters in the academy and it is working well, however the environment is always runing on training mode

I made some tests by playing with window width and height and no matter what I chose for the train_mode parameter (Trueor False) in env.reset(), the game is runing with training mode only, never inference

Am I missing something ? Also I think that it is a great idea to put these parameters as arguments to UnityEnvironment

chriselion commented 4 years ago

By default, when you connect with python, the academy thinks it's in "training" mode. You can change the behavior in Agents (in 0.12.0) by setting their BehaviorParameters Behavior Type to "Inference Only"; they'll use inference, but the Academy's decision of whether to use the "training" or "inference" configurations is based solely on whether it's connected to an external processes (i.e. Python).

If you want full control over the settings in 0.12.0, I'd recommend you do the equivalent of Academy.ConfigureEnvironmentHelper inside your Academy.Step implementation (unfortunately doing it in InitializeAcademy will get overwritten)

valentinmace commented 4 years ago

Thanks a lot

github-actions[bot] commented 3 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.