|
|
|
|
|
|
from mlagents.envs.communicator_objects.agent_info_pb2 import AgentInfoProto |
|
|
|
from mlagents.envs.communicator_objects.brain_parameters_pb2 import BrainParametersProto |
|
|
|
from mlagents.envs.timers import hierarchical_timer, timed |
|
|
|
from typing import Dict, List, Optional |
|
|
|
from typing import Dict, List, NamedTuple, Optional |
|
|
|
class CameraResolution(NamedTuple): |
|
|
|
height: int |
|
|
|
width: int |
|
|
|
gray_scale: bool |
|
|
|
|
|
|
|
@property |
|
|
|
def num_channels(self) -> int: |
|
|
|
return 1 if self.gray_scale else 3 |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def from_proto(p): |
|
|
|
return CameraResolution(height=p.height, width=p.width, gray_scale=p.gray_scale) |
|
|
|
|
|
|
|
|
|
|
|
class BrainParameters: |
|
|
|
def __init__( |
|
|
|
self, |
|
|
|
|
|
|
camera_resolutions: List[Dict], |
|
|
|
camera_resolutions: List[CameraResolution], |
|
|
|
vector_action_space_size: List[int], |
|
|
|
vector_action_descriptions: List[str], |
|
|
|
vector_action_space_type: int, |
|
|
|
|
|
|
:return: BrainParameter object. |
|
|
|
""" |
|
|
|
resolution = [ |
|
|
|
{"height": x.height, "width": x.width, "blackAndWhite": x.gray_scale} |
|
|
|
for x in brain_param_proto.camera_resolutions |
|
|
|
CameraResolution.from_proto(x) for x in brain_param_proto.camera_resolutions |
|
|
|
] |
|
|
|
brain_params = BrainParameters( |
|
|
|
brain_param_proto.brain_name, |
|
|
|
|
|
|
obs = [ |
|
|
|
BrainInfo.process_pixels( |
|
|
|
x.visual_observations[i], |
|
|
|
brain_params.camera_resolutions[i]["blackAndWhite"], |
|
|
|
brain_params.camera_resolutions[i].gray_scale, |
|
|
|
) |
|
|
|
for x in agent_info_list |
|
|
|
] |
|
|
|