|
|
|
|
|
|
/// <param name="brainParameters">
|
|
|
|
/// The BrainParameters that are used verify the compatibility with the InferenceEngine
|
|
|
|
/// </param>
|
|
|
|
/// <param name="sensorComponents">Attached sensor components</param>
|
|
|
|
/// <param name="sensors">Attached sensor components</param>
|
|
|
|
SensorComponent[] sensorComponents, ActuatorComponent[] actuatorComponents, |
|
|
|
ISensor[] sensors, ActuatorComponent[] actuatorComponents, |
|
|
|
int observableAttributeTotalSize = 0, |
|
|
|
BehaviorType behaviorType = BehaviorType.Default) |
|
|
|
{ |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
failedModelChecks.AddRange( |
|
|
|
CheckInputTensorPresence(model, brainParameters, memorySize, sensorComponents) |
|
|
|
CheckInputTensorPresence(model, brainParameters, memorySize, sensors) |
|
|
|
CheckInputTensorShape(model, brainParameters, sensorComponents, observableAttributeTotalSize) |
|
|
|
CheckInputTensorShape(model, brainParameters, sensors, observableAttributeTotalSize) |
|
|
|
); |
|
|
|
failedModelChecks.AddRange( |
|
|
|
CheckOutputTensorShape(model, brainParameters, actuatorComponents) |
|
|
|
|
|
|
/// <param name="memory">
|
|
|
|
/// The memory size that the model is expecting.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="sensorComponents">Array of attached sensor components</param>
|
|
|
|
/// <param name="sensors">Array of attached sensor components</param>
|
|
|
|
/// <returns>
|
|
|
|
/// A IEnumerable of string corresponding to the failed input presence checks.
|
|
|
|
/// </returns>
|
|
|
|
|
|
|
int memory, |
|
|
|
SensorComponent[] sensorComponents |
|
|
|
ISensor[] sensors |
|
|
|
) |
|
|
|
{ |
|
|
|
var failedModelChecks = new List<string>(); |
|
|
|
|
|
|
// If there are not enough Visual Observation Input compared to what the
|
|
|
|
// sensors expect.
|
|
|
|
var visObsIndex = 0; |
|
|
|
var varLenIndex = 0; |
|
|
|
for (var sensorIndex = 0; sensorIndex < sensorComponents.Length; sensorIndex++) |
|
|
|
for (var sensorIndex = 0; sensorIndex < sensors.Length; sensorIndex++) |
|
|
|
var sensor = sensorComponents[sensorIndex]; |
|
|
|
var sensor = sensors[sensorIndex]; |
|
|
|
if (sensor.GetObservationShape().Length == 3) |
|
|
|
{ |
|
|
|
if (!tensorsNames.Contains( |
|
|
|
|
|
|
if (sensor.GetObservationShape().Length == 2) |
|
|
|
{ |
|
|
|
if (!tensorsNames.Contains( |
|
|
|
TensorNames.ObservationPlaceholderPrefix + varLenIndex)) |
|
|
|
TensorNames.ObservationPlaceholderPrefix + sensorIndex)) |
|
|
|
$"for sensor component {varLenIndex} ({sensor.GetType().Name})."); |
|
|
|
varLenIndex++; |
|
|
|
$"for sensor component {sensorIndex} ({sensor.GetType().Name})."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
/// Checks that the shape of the visual observation input placeholder is the same as the corresponding sensor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tensorProxy">The tensor that is expected by the model</param>
|
|
|
|
/// <param name="sensorComponent">The sensor that produces the visual observation.</param>
|
|
|
|
/// <param name="sensor">The sensor that produces the visual observation.</param>
|
|
|
|
TensorProxy tensorProxy, SensorComponent sensorComponent) |
|
|
|
TensorProxy tensorProxy, ISensor sensor) |
|
|
|
var shape = sensorComponent.GetObservationShape(); |
|
|
|
var shape = sensor.GetObservationShape(); |
|
|
|
var heightBp = shape[0]; |
|
|
|
var widthBp = shape[1]; |
|
|
|
var pixelBp = shape[2]; |
|
|
|
|
|
|
/// Checks that the shape of the rank 2 observation input placeholder is the same as the corresponding sensor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tensorProxy">The tensor that is expected by the model</param>
|
|
|
|
/// <param name="sensorComponent">The sensor that produces the visual observation.</param>
|
|
|
|
/// <param name="sensor">The sensor that produces the visual observation.</param>
|
|
|
|
TensorProxy tensorProxy, SensorComponent sensorComponent) |
|
|
|
TensorProxy tensorProxy, ISensor sensor) |
|
|
|
var shape = sensorComponent.GetObservationShape(); |
|
|
|
var shape = sensor.GetObservationShape(); |
|
|
|
var dim1Bp = shape[0]; |
|
|
|
var dim2Bp = shape[1]; |
|
|
|
var dim1T = tensorProxy.Channels; |
|
|
|
|
|
|
/// <param name="brainParameters">
|
|
|
|
/// The BrainParameters that are used verify the compatibility with the InferenceEngine
|
|
|
|
/// </param>
|
|
|
|
/// <param name="sensorComponents">Attached sensors</param>
|
|
|
|
/// <param name="sensors">Attached sensors</param>
|
|
|
|
Model model, BrainParameters brainParameters, SensorComponent[] sensorComponents, |
|
|
|
Model model, BrainParameters brainParameters, ISensor[] sensors, |
|
|
|
new Dictionary<string, Func<BrainParameters, TensorProxy, SensorComponent[], int, string>>() |
|
|
|
new Dictionary<string, Func<BrainParameters, TensorProxy, ISensor[], int, string>>() |
|
|
|
{ |
|
|
|
{TensorNames.VectorObservationPlaceholder, CheckVectorObsShape}, |
|
|
|
{TensorNames.PreviousActionPlaceholder, CheckPreviousActionShape}, |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var visObsIndex = 0; |
|
|
|
var varLenIndex = 0; |
|
|
|
for (var sensorIndex = 0; sensorIndex < sensorComponents.Length; sensorIndex++) |
|
|
|
for (var sensorIndex = 0; sensorIndex < sensors.Length; sensorIndex++) |
|
|
|
var sensorComponent = sensorComponents[sensorIndex]; |
|
|
|
if (sensorComponent.GetObservationShape().Length == 3) |
|
|
|
var sens = sensors[sensorIndex]; |
|
|
|
if (sens.GetObservationShape().Length == 3) |
|
|
|
(bp, tensor, scs, i) => CheckVisualObsShape(tensor, sensorComponent); |
|
|
|
(bp, tensor, scs, i) => CheckVisualObsShape(tensor, sens); |
|
|
|
if (sensorComponent.GetObservationShape().Length == 2) |
|
|
|
if (sens.GetObservationShape().Length == 2) |
|
|
|
tensorTester[TensorNames.ObservationPlaceholderPrefix + varLenIndex] = |
|
|
|
(bp, tensor, scs, i) => CheckRankTwoObsShape(tensor, sensorComponent); |
|
|
|
varLenIndex++; |
|
|
|
tensorTester[TensorNames.ObservationPlaceholderPrefix + sensorIndex] = |
|
|
|
(bp, tensor, scs, i) => CheckRankTwoObsShape(tensor, sens); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
{ |
|
|
|
var tester = tensorTester[tensor.name]; |
|
|
|
var error = tester.Invoke(brainParameters, tensor, sensorComponents, observableAttributeTotalSize); |
|
|
|
var error = tester.Invoke(brainParameters, tensor, sensors, observableAttributeTotalSize); |
|
|
|
if (error != null) |
|
|
|
{ |
|
|
|
failedModelChecks.Add(error); |
|
|
|
|
|
|
/// The BrainParameters that are used verify the compatibility with the InferenceEngine
|
|
|
|
/// </param>
|
|
|
|
/// <param name="tensorProxy">The tensor that is expected by the model</param>
|
|
|
|
/// <param name="sensorComponents">Array of attached sensor components</param>
|
|
|
|
/// <param name="sensors">Array of attached sensor components</param>
|
|
|
|
/// <param name="observableAttributeTotalSize">Sum of the sizes of all ObservableAttributes.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// If the Check failed, returns a string containing information about why the
|
|
|
|
|
|
|
BrainParameters brainParameters, TensorProxy tensorProxy, SensorComponent[] sensorComponents, |
|
|
|
BrainParameters brainParameters, TensorProxy tensorProxy, ISensor[] sensors, |
|
|
|
int observableAttributeTotalSize) |
|
|
|
{ |
|
|
|
var vecObsSizeBp = brainParameters.VectorObservationSize; |
|
|
|
|
|
|
var totalVectorSensorSize = 0; |
|
|
|
foreach (var sensorComp in sensorComponents) |
|
|
|
foreach (var sens in sensors) |
|
|
|
if (sensorComp.GetObservationShape().Length == 1) |
|
|
|
if ((sens.GetObservationShape().Length == 1)) |
|
|
|
totalVectorSensorSize += sensorComp.GetObservationShape()[0]; |
|
|
|
totalVectorSensorSize += sens.GetObservationShape()[0]; |
|
|
|
if (vecObsSizeBp * numStackedVector + totalVectorSensorSize != totalVecObsSizeT) |
|
|
|
if (totalVectorSensorSize != totalVecObsSizeT) |
|
|
|
foreach (var sensorComp in sensorComponents) |
|
|
|
foreach (var sensorComp in sensors) |
|
|
|
{ |
|
|
|
if (sensorComp.GetObservationShape().Length == 1) |
|
|
|
{ |
|
|
|
|
|
|
$"but received: \n" + |
|
|
|
$"Vector observations: {vecObsSizeBp} x {numStackedVector}\n" + |
|
|
|
$"Total [Observable] attributes: {observableAttributeTotalSize}\n" + |
|
|
|
$"SensorComponent sizes: {sensorSizes}."; |
|
|
|
$"Sensor sizes: {sensorSizes}."; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
/// The BrainParameters that are used verify the compatibility with the InferenceEngine
|
|
|
|
/// </param>
|
|
|
|
/// <param name="tensorProxy"> The tensor that is expected by the model</param>
|
|
|
|
/// <param name="sensorComponents">Array of attached sensor components (unused).</param>
|
|
|
|
/// <param name="sensors">Array of attached sensor components (unused).</param>
|
|
|
|
SensorComponent[] sensorComponents, int observableAttributeTotalSize) |
|
|
|
ISensor[] sensors, int observableAttributeTotalSize) |
|
|
|
{ |
|
|
|
var numberActionsBp = brainParameters.ActionSpec.NumDiscreteActions; |
|
|
|
var numberActionsT = tensorProxy.shape[tensorProxy.shape.Length - 1]; |
|
|
|