From docs: LLAPI Documentation - Unity ML-Agents Toolkit.
capture_frame_rate: Instructs the simulation to consider time between updates to always be constant, regardless of the actual frame rate.
But in my practice, The lower capture_frame_rate
, the FPS higher.
My code:
import time
from mlagents_envs.environment import UnityEnvironment
from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
from mlagents_envs.envs.unity_gym_env import UnityToGymWrapper
channel = EngineConfigurationChannel()
channel.set_configuration_parameters(
time_scale=1,
width=320,
height=180,
# target_frame_rate=30,
capture_frame_rate=1,
)
unity_env = UnityEnvironment(file_name="...../AI-Playground.exe", side_channels=[channel])
env = UnityToGymWrapper(unity_env, uint8_visual=True)
obs = env.reset()
start_time = time.perf_counter()
frame_count = 0
fps = 0
while True:
obs, reward, done, info = env.step([0, 0])
duration = time.perf_counter() - start_time
frame_count += 1
if duration >= 1:
fps = frame_count / duration
display(fps, clear=True)
start_time = time.perf_counter()
frame_count = 0
if done:
obs = env.reset()