浏览代码

Fixes missing camera resolution info in demos (#2523)

/develop-gpu-test
GitHub 5 年前
当前提交
9b004c54
共有 2 个文件被更改,包括 62 次插入9 次删除
  1. 36
      UnitySDK/Assets/ML-Agents/Editor/DemonstrationDrawer.cs
  2. 35
      UnitySDK/Assets/ML-Agents/Scripts/BrainParameters.cs

36
UnitySDK/Assets/ML-Agents/Editor/DemonstrationDrawer.cs


}
/// <summary>
/// Constructs complex label for each CameraResolution object.
/// An example of this could be `[ 84 X 84 ]`
/// for a single camera with 84 pixels height and width.
/// </summary>
private static string BuildCameraResolutionLabel(SerializedProperty cameraArray)
{
var numCameras = cameraArray.arraySize;
var cameraLabel = new StringBuilder("[ ");
for (var i = 0; i < numCameras; i++)
{
var camHeightPropName =
cameraArray.GetArrayElementAtIndex(i).FindPropertyRelative("height");
cameraLabel.Append(camHeightPropName.intValue);
cameraLabel.Append(" X ");
var camWidthPropName =
cameraArray.GetArrayElementAtIndex(i).FindPropertyRelative("width");
cameraLabel.Append(camWidthPropName.intValue);
if (i < numCameras - 1)
{
cameraLabel.Append(", ");
}
}
cameraLabel.Append(" ]");
return cameraLabel.ToString();
}
/// <summary>
/// Renders Inspector UI for Brain Parameters of Demonstration.
/// </summary>
void MakeBrainParametersProperty(SerializedProperty property)

var vecObsSizeLabel = vecObsSizeProp.displayName + ": " + vecObsSizeProp.intValue;
var numStackedLabel = numStackedProp.displayName + ": " + numStackedProp.intValue;
var vecActSizeLabel = actSizeProperty.displayName + ": " + BuildActionArrayLabel(actSizeProperty);
var camResLabel = camResProp.displayName + ": " + camResProp.arraySize;
var actSpaceTypeLabel = actSpaceTypeProp.displayName + ": " + (SpaceType) actSpaceTypeProp.enumValueIndex;
var vecActSizeLabel =
actSizeProperty.displayName + ": " + BuildActionArrayLabel(actSizeProperty);
var camResLabel = camResProp.displayName + ": " + BuildCameraResolutionLabel(camResProp);
var actSpaceTypeLabel = actSpaceTypeProp.displayName + ": " +
(SpaceType) actSpaceTypeProp.enumValueIndex;
EditorGUILayout.LabelField(vecObsSizeLabel);
EditorGUILayout.LabelField(numStackedLabel);

35
UnitySDK/Assets/ML-Agents/Scripts/BrainParameters.cs


[Range(1, 50)] public int numStackedVectorObservations = 1;
public int[] vectorActionSize = new int[1]{1};
public int[] vectorActionSize = new int[1] {1};
/**< \brief If continuous : The length of the float vector that represents
* the action
* <br> If discrete : The number of possible values the action can take*/

public SpaceType vectorActionSpaceType = SpaceType.discrete;
/**< \brief Defines if the action is discrete or continuous */
/// <summary>
/// Converts a Brain into to a Protobuff BrainInfoProto so it can be sent
/// </summary>

public CommunicatorObjects.BrainParametersProto
public CommunicatorObjects.BrainParametersProto
ToProto(string name, bool isTraining)
{
var brainParametersProto = new CommunicatorObjects.BrainParametersProto

VectorActionSize = {vectorActionSize},
VectorActionSpaceType =
(CommunicatorObjects.SpaceTypeProto)vectorActionSpaceType,
(CommunicatorObjects.SpaceTypeProto) vectorActionSpaceType,
BrainName = name,
IsTraining = isTraining
};

GrayScale = res.blackAndWhite
});
}
}
/// <summary>
/// Converts Resolution protobuf array to C# Resolution array.
/// </summary>
private static Resolution[] ResolutionProtoToNative(
CommunicatorObjects.ResolutionProto[] resolutionProtos)
{
var localCameraResolutions = new Resolution[resolutionProtos.Length];
for (var i = 0; i < resolutionProtos.Length; i++)
{
localCameraResolutions[i] = new Resolution
{
height = resolutionProtos[i].Height,
width = resolutionProtos[i].Width,
blackAndWhite = resolutionProtos[i].GrayScale
};
}
return localCameraResolutions;
cameraResolutions = ResolutionProtoToNative(
brainParametersProto.CameraResolutions.ToArray()
);
vectorActionSpaceType = (SpaceType)brainParametersProto.VectorActionSpaceType;
vectorActionSpaceType = (SpaceType) brainParametersProto.VectorActionSpaceType;
}
/// <summary>

正在加载...
取消
保存