def group_spec_to_brain_parameters( name: str, group_spec ) -> BrainParameters: vec_size = np.sum( [shape[0] for shape in group_spec['observation_shapes'] if len(shape) == 1] ) vis_sizes = [shape for shape in group_spec['observation_shapes'] if len(shape) == 3] cam_res = [CameraResolution(s[0], s[1], s[2]) for s in vis_sizes] a_size: List[int] = [] if group_spec['action_type'] == 'DISCRETE': a_size += list(group_spec['action_shape']) vector_action_space_type = 0 else: a_size += [group_spec.action_size] vector_action_space_type = 1 return BrainParameters( brain_name=name, vector_observation_space_size=int(vec_size), camera_resolutions=cam_res, vector_action_space_size=a_size, vector_action_descriptions=[], vector_action_space_type=vector_action_space_type )
def create_mock_brainparams( number_visual_observations=0, vector_action_space_type="continuous", vector_observation_space_size=3, vector_action_space_size=None, ): """ Creates a mock BrainParameters object with parameters. """ # Avoid using mutable object as default param if vector_action_space_size is None: vector_action_space_size = [2] mock_brain = mock.Mock() mock_brain.return_value.number_visual_observations = number_visual_observations mock_brain.return_value.vector_action_space_type = vector_action_space_type mock_brain.return_value.vector_observation_space_size = ( vector_observation_space_size ) camrez = CameraResolution(height=84, width=84, num_channels=3) mock_brain.return_value.camera_resolutions = [camrez] * number_visual_observations mock_brain.return_value.vector_action_space_size = vector_action_space_size mock_brain.return_value.brain_name = "MockBrain" return mock_brain()