Example #1
0
        /// <summary>
        /// Must be called within OnEditorGUI()
        /// </summary>
        void DisplayFailedModelChecks()
        {
            if (m_RequireReload && m_TimeSinceModelReload > k_TimeBetweenModelReloads)
            {
                m_RequireReload        = false;
                m_TimeSinceModelReload = 0;
            }
            // Display all failed checks
            D.logEnabled = false;
            Model barracudaModel     = null;
            var   model              = (NNModel)serializedObject.FindProperty("m_Model").objectReferenceValue;
            var   behaviorParameters = (BehaviorParameters)target;

            // Grab the sensor components, since we need them to determine the observation sizes.
            SensorComponent[] sensorComponents;
            if (behaviorParameters.UseChildSensors)
            {
                sensorComponents = behaviorParameters.GetComponentsInChildren <SensorComponent>();
            }
            else
            {
                sensorComponents = behaviorParameters.GetComponents <SensorComponent>();
            }

            // Get the total size of the sensors generated by ObservableAttributes.
            // If there are any errors (e.g. unsupported type, write-only properties), display them too.
            int observableAttributeSensorTotalSize = 0;
            var agent = behaviorParameters.GetComponent <Agent>();

            if (agent != null && behaviorParameters.ObservableAttributeHandling != ObservableAttributeOptions.Ignore)
            {
                List <string> observableErrors = new List <string>();
                observableAttributeSensorTotalSize = ObservableAttribute.GetTotalObservationSize(agent, false, observableErrors);
                foreach (var check in observableErrors)
                {
                    EditorGUILayout.HelpBox(check, MessageType.Warning);
                }
            }

            var brainParameters = behaviorParameters.BrainParameters;

            if (model != null)
            {
                barracudaModel = ModelLoader.Load(model);
            }
            if (brainParameters != null)
            {
                var failedChecks = Inference.BarracudaModelParamLoader.CheckModel(
                    barracudaModel, brainParameters, sensorComponents,
                    observableAttributeSensorTotalSize, behaviorParameters.BehaviorType
                    );
                foreach (var check in failedChecks)
                {
                    if (check != null)
                    {
                        EditorGUILayout.HelpBox(check, MessageType.Warning);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Must be called within OnEditorGUI()
        /// </summary>
        void DisplayFailedModelChecks()
        {
            if (m_RequireReload && m_TimeSinceModelReload > k_TimeBetweenModelReloads)
            {
                m_RequireReload        = false;
                m_TimeSinceModelReload = 0;
            }
            // Display all failed checks
            D.logEnabled = false;
            Model barracudaModel     = null;
            var   model              = (NNModel)serializedObject.FindProperty(k_ModelName).objectReferenceValue;
            var   behaviorParameters = (BehaviorParameters)target;

            // Grab the sensor components, since we need them to determine the observation sizes.
            // TODO make these methods of BehaviorParameters
            var agent = behaviorParameters.gameObject.GetComponent <Agent>();

            if (agent == null)
            {
                return;
            }
            agent.sensors = new List <ISensor>();
            agent.InitializeSensors();
            var sensors = agent.sensors.ToArray();

            ActuatorComponent[] actuatorComponents;
            if (behaviorParameters.UseChildActuators)
            {
                actuatorComponents = behaviorParameters.GetComponentsInChildren <ActuatorComponent>();
            }
            else
            {
                actuatorComponents = behaviorParameters.GetComponents <ActuatorComponent>();
            }

            // Get the total size of the sensors generated by ObservableAttributes.
            // If there are any errors (e.g. unsupported type, write-only properties), display them too.
            int observableAttributeSensorTotalSize = 0;

            if (agent != null && behaviorParameters.ObservableAttributeHandling != ObservableAttributeOptions.Ignore)
            {
                List <string> observableErrors = new List <string>();
                observableAttributeSensorTotalSize = ObservableAttribute.GetTotalObservationSize(agent, false, observableErrors);
                foreach (var check in observableErrors)
                {
                    EditorGUILayout.HelpBox(check, MessageType.Warning);
                }
            }

            var brainParameters = behaviorParameters.BrainParameters;

            if (model != null)
            {
                barracudaModel = ModelLoader.Load(model);
            }
            if (brainParameters != null)
            {
                var failedChecks = Inference.BarracudaModelParamLoader.CheckModel(
                    barracudaModel, brainParameters, sensors, actuatorComponents,
                    observableAttributeSensorTotalSize, behaviorParameters.BehaviorType, behaviorParameters.DeterministicInference
                    );
                foreach (var check in failedChecks)
                {
                    if (check != null)
                    {
                        switch (check.CheckType)
                        {
                        case CheckTypeEnum.Info:
                            EditorGUILayout.HelpBox(check.Message, MessageType.Info);
                            break;

                        case CheckTypeEnum.Warning:
                            EditorGUILayout.HelpBox(check.Message, MessageType.Warning);
                            break;

                        case CheckTypeEnum.Error:
                            EditorGUILayout.HelpBox(check.Message, MessageType.Error);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }