Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Why does my visual observation look so strange when I load the UnityEnvironment in Python?

Discussion in 'ML-Agents' started by laukinonntu, Mar 7, 2024.

  1. laukinonntu

    laukinonntu

    Joined:
    Nov 22, 2023
    Posts:
    1
    comparison.png

    On the left is what the observation looks like in the unity editor, while on the right is what comes up when I try to render the camera observation after loading the environment in python. The colors are strange and there are these patterned vertical bars across the screen.

    However, if I load the example scenes like VisualFoodCollector, the observation appears normal. What could be the problem?

    Here is my code:
    Code (CSharp):
    1. from mlagents_envs.envs.unity_parallel_env import UnityParallelEnv
    2. from mlagents_envs.environment import UnityEnvironment
    3. # This is a non-blocking call that only loads the environment.
    4. unity_env = UnityEnvironment(file_name="../HMArena/Build/HMArena", seed=1, side_channels=[])
    5. # Start interacting with the environment.
    6. env = UnityParallelEnv(unity_env)
    7.  
    8. import numpy as np
    9. import matplotlib.pyplot as plt
    10. import cv2
    11.  
    12. env.reset()
    13. print(env.action_space('SimpleMouse?team=0?agent_id=0'))
    14. for agent in env.agents:
    15.     obs = env.reset()['SimpleMouse?team=0?agent_id=0']['observation'][0]
    16.     obs = obs.transpose(1, 2, 0)
    17.     print(np.shape(obs))
    18.     print(obs)
    19.     plt.imshow(obs)
    20.