浏览代码

Project settings for perception and assigning endpoint

/solo_support
Steve Borkman 3 年前
当前提交
eb7c733a
共有 18 个文件被更改,包括 262 次插入131 次删除
  1. 93
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  2. 4
      com.unity.perception/Runtime/GroundTruth/ConsumerEndpoint.cs
  3. 8
      com.unity.perception/Runtime/GroundTruth/Consumers/NoOpConsumer.cs
  4. 6
      com.unity.perception/Runtime/GroundTruth/Consumers/OldPerceptionConsumer.cs
  5. 9
      com.unity.perception/Runtime/GroundTruth/Consumers/SoloConsumer.cs
  6. 5
      com.unity.perception/Runtime/GroundTruth/Consumers/SoloMessageBuilder.cs
  7. 32
      com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs
  8. 6
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  9. 5
      com.unity.perception/Tests/Runtime/GroundTruthTests/CollectEndpoint.cs
  10. 53
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureTests.cs
  11. 12
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
  12. 4
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs
  13. 99
      com.unity.perception/Editor/GroundTruth/SettingsProvider.cs
  14. 3
      com.unity.perception/Editor/GroundTruth/SettingsProvider.cs.meta
  15. 3
      com.unity.perception/Runtime/Settings.meta
  16. 40
      com.unity.perception/Runtime/Settings/PerceptionSettings.cs
  17. 11
      com.unity.perception/Runtime/Settings/PerceptionSettings.cs.meta

93
com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Perception.GroundTruth.Exporters;
using UnityEngine.Perception.Settings;
namespace UnityEditor.Perception.GroundTruth
{

m_LabelersList.drawElementCallback = DrawElement;
m_LabelersList.onAddCallback += OnAdd;
m_LabelersList.onRemoveCallback += OnRemove;
#if false
m_OutputMode = PlayerPrefs.GetString(SimulationState.outputFormatMode);
m_ExporterList = TypeCache.GetTypesDerivedFrom<IDatasetExporter>().Select(exporter => exporter.Name).ToArray();
if (m_ExporterList.Any())
m_OutputModeIndex = Array.IndexOf(m_ExporterList, m_OutputMode);
m_OutputMode = PlayerPrefs.GetString(SimulationState.outputFormatMode, "Perception");
#endif
}
float GetElementHeight(int index)

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.description)), new GUIContent("Description", "Provide a description for this camera (optional)."));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.showVisualizations)), new GUIContent("Show Labeler Visualizations", "Display realtime visualizations for labelers that are currently active on this camera."));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.captureRgbImages)),new GUIContent("Save Camera RGB Output to Disk", "For each captured frame, save an RGB image of the camera's output to disk."));
#if false
if (m_ExporterList.Any())
{
if (m_OutputModeIndex < 0)
{
m_OutputMode = nameof(PerceptionExporter);
Debug.LogWarning($"Could not find the output format \'{m_OutputMode}\' in the list of available exporters, setting the exporter to \'{m_OutputMode}\'");
m_OutputModeIndex = Array.IndexOf(m_ExporterList, m_OutputMode);
}
var selected = EditorGUILayout.Popup(new GUIContent("Output Format", ""), m_OutputModeIndex, m_ExporterList);
if (m_OutputModeIndex != selected)
{
m_OutputModeIndex = selected;
m_OutputMode = m_ExporterList[selected];
PlayerPrefs.SetString(SimulationState.outputFormatMode, m_OutputMode);
}
}
#endif
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.captureTriggerMode)),new GUIContent("Capture Trigger Mode", $"The method of triggering captures for this camera. In {nameof(CaptureTriggerMode.Scheduled)} mode, captures happen automatically based on a start frame and frame delta time. In {nameof(CaptureTriggerMode.Manual)} mode, captures should be triggered manually through calling the {nameof(perceptionCamera.RequestCapture)} method of {nameof(PerceptionCamera)}."));
GUILayout.Space(5);

GUILayout.Space(15);
m_LabelersList.DoLayoutList();
}
var s = new GUIStyle(EditorStyles.textField);
s.wordWrap = true;
var defaultColor = s.normal.textColor;
var dir = PlayerPrefs.GetString(string.Empty, string.Empty);
if (dir != string.Empty)
{
EditorGUILayout.LabelField("Latest Generated Dataset");
GUILayout.BeginVertical("TextArea");
s.normal.textColor = Color.green;
EditorGUILayout.LabelField(dir, s);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Show Folder"))
if (PerceptionSettings.Endpoint == null)
EditorUtility.RevealInFinder(dir);
}
if (GUILayout.Button("Copy Path"))
{
GUIUtility.systemCopyBuffer = dir;
EditorGUILayout.HelpBox("Currently there is not a consumer endpoint setup for this simulation. " +
"One can be assigned in Project Settings -> Perception -> Active Endpoint", MessageType.Error);
GUILayout.Space(15);
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
GUILayout.Space(10);
var userBaseDir = PlayerPrefs.GetString(string.Empty, string.Empty);
if (userBaseDir == string.Empty)
{
var folder = PlayerPrefs.GetString(string.Empty, string.Empty);
userBaseDir = folder != string.Empty ? folder : Application.persistentDataPath;
}
EditorGUILayout.LabelField("Output Base Folder");
GUILayout.BeginVertical("TextArea");
s.normal.textColor = defaultColor;
EditorGUILayout.LabelField(userBaseDir, s);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Change Folder"))
{
var path = EditorUtility.OpenFolderPanel("Choose Output Folder", "", "");
if (path.Length != 0)
{
Debug.Log($"Chose path: {path}");
// PlayerPrefs.SetString(SimulationState.userBaseDirectoryKey, path);
}
m_LabelersList.DoLayoutList();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.Space(15);
EditorGUILayout.HelpBox("Asynchronous shader compilation may result in invalid data in beginning frames. " +
"This can be disabled in Project Settings -> Editor -> Asynchronous Shader Compilation", MessageType.Warning);
}

hdRenderPipelineAsset.currentPlatformRenderPipelineSettings.supportedLitShaderMode ==
UnityEngine.Rendering.HighDefinition.RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly)
{
GUILayout.Space(15);
EditorGUILayout.HelpBox("Deferred Only shader mode is not supported by rendering-based labelers. " +
"For correct labeler output, switch Lit Shader Mode to Both or Forward Only in your HD Render Pipeline Asset", MessageType.Error);
}

4
com.unity.perception/Runtime/GroundTruth/ConsumerEndpoint.cs


namespace UnityEngine.Perception.GroundTruth
{
public abstract class ConsumerEndpoint
[Serializable]
public abstract class ConsumerEndpoint : ScriptableObject, ICloneable
{
IEnumerator WaitForComplete()
{

#else
protected abstract bool IsComplete();
public abstract object Clone();
#endif
/// <summary>

8
com.unity.perception/Runtime/GroundTruth/Consumers/NoOpConsumer.cs


using UnityEngine.Perception.GroundTruth.DataModel;
using System;
using UnityEngine.Perception.GroundTruth.DataModel;
namespace UnityEngine.Perception.GroundTruth.Consumers
{

{
return true;
}
public override object Clone()
{
return CreateInstance<NoOpConsumer>();
}
public override void OnSimulationStarted(SimulationMetadata metadata)

6
com.unity.perception/Runtime/GroundTruth/Consumers/OldPerceptionConsumer.cs


return true;
}
public override object Clone()
{
var cloned = ScriptableObject.CreateInstance<OldPerceptionConsumer>();
return cloned;
}
internal string VerifyDirectoryWithGuidExists(string directoryPrefix, bool appendGuid = true)
{
var dirs = Directory.GetDirectories(m_CurrentPath);

9
com.unity.perception/Runtime/GroundTruth/Consumers/SoloConsumer.cs


namespace UnityEngine.Perception.GroundTruth.Consumers
{
[CreateAssetMenu(fileName = "SoloConfiguration", menuName = "Perception/Endpoint/Solo Consumer", order = 3)]
public class SoloConsumer : ConsumerEndpoint
{
public string _baseDirectory = "D:/PerceptionOutput/SoloConsumer";

protected override bool IsComplete()
{
return m_IsComplete;
}
public override object Clone()
{
var newOne = ScriptableObject.CreateInstance<SoloConsumer>();
newOne._baseDirectory = _baseDirectory;
newOne.soloDatasetName = soloDatasetName;
return newOne;
}
public override void OnSimulationStarted(SimulationMetadata metadata)

5
com.unity.perception/Runtime/GroundTruth/Consumers/SoloMessageBuilder.cs


return true;
}
public override object Clone()
{
return ScriptableObject.CreateInstance<SoloMessageBuilder>();
}
SimulationMetadata m_CurrentMetadata;
public override void OnSimulationStarted(SimulationMetadata metadata)

32
com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using UnityEngine.Perception.Settings;
#pragma warning disable 649
namespace UnityEngine.Perception.GroundTruth

internal bool IsValid(string id) => currentSimulation.Contains(id);
ConsumerEndpoint m_OverrideEndpoint = null;
internal void OverrideEndpoint(ConsumerEndpoint endpoint)
{
m_OverrideEndpoint = endpoint;
}
#if false
// TODO why is this static?
public static ConsumerEndpoint[] endpoints => new[] { s_Endpoint };
public static void AddEndpoint(ConsumerEndpoint endpoint)
{
// Only support one for right now
SetEndpoint(endpoint);
}
public static void SetEndpoint(ConsumerEndpoint endpoint)
{
// TODO I think that we need to do some checking to make sure we're not running

Debug.Log("Not setting endpoint type");
return false;
}
static SimulationState CreateSimulationData()
#endif
SimulationState CreateSimulationData()
if (s_Endpoint != null) return new SimulationState(s_Endpoint.GetType());
if (s_EndpointType != null) return new SimulationState(s_EndpointType);
throw new InvalidOperationException("Dataset capture cannot create a new simulation state without either a valid consumer endpoint or an endpoint type to instantiate.");
if (m_OverrideEndpoint == null && PerceptionSettings.Endpoint == null)
{
throw new InvalidOperationException("An endpoint has not been set for dataset capture");
}
var endpoint = m_OverrideEndpoint ? m_OverrideEndpoint : PerceptionSettings.Endpoint.Clone();
return new SimulationState(endpoint as ConsumerEndpoint);
}
[RuntimeInitializeOnLoadMethod]

6
com.unity.perception/Runtime/GroundTruth/SimulationState.cs


//A sensor will be triggered if sequenceTime is within includeThreshold seconds of the next trigger
const float k_SimulationTimingAccuracy = 0.01f;
public SimulationState(Type endpointType)
public SimulationState(ConsumerEndpoint endpoint)
{
ExecutionState = ExecutionStateType.NotStarted;

perceptionVersion = DatasetCapture.PerceptionVersion,
};
if (!endpointType.IsSubclassOf(typeof(ConsumerEndpoint)))
throw new InvalidOperationException($"Cannot add non-endpoint type {endpointType.Name} to consumer endpoint list");
consumerEndpoint = (ConsumerEndpoint)Activator.CreateInstance(endpointType);
consumerEndpoint = endpoint;
}
bool readyToShutdown => !m_PendingFrames.Any();

5
com.unity.perception/Tests/Runtime/GroundTruthTests/CollectEndpoint.cs


return true;
}
public override object Clone()
{
return ScriptableObject.CreateInstance<CollectEndpoint>();
}
public override void OnSimulationStarted(SimulationMetadata metadata)
{
currentRun = new SimulationRun

53
com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureTests.cs


const int delta = 1;
const int framesBetween = 0;
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var sensorHandle = RegisterSensor(id, modality, def, firstFrame, mode, delta, framesBetween);
Assert.IsTrue(sensorHandle.IsValid);

[UnityTest]
public IEnumerator ReportCaptureAsync_TimesOut()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
SimulationState.TimeOutFrameCount = 5;
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);

[UnityTest]
public IEnumerator ReportCaptureAsync_DoesNotTimeOut()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
SimulationState.TimeOutFrameCount = 5;
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);

var sensor = CreateMocRgbCapture();
sensorHandle.ReportSensor(sensor);
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
yield return null;
DatasetCapture.Instance.ResetSimulation();

(1, 1, 2)
};
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 2, 0);
var sensor = new RgbSensor();

[UnityTest]
public IEnumerator ReportAnnotation_AddsProperJsonToCapture()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensor = new RgbSensor();

[UnityTest]
public IEnumerator ReportAnnotationValues_ReportsProperJson()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensor = new RgbSensor();

[UnityTest]
public IEnumerator AnnotationAsyncInvalid_TimesOut()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
SimulationState.TimeOutFrameCount = 100;

[UnityTest]
public IEnumerator AnnotationAsyncIsValid_ReturnsProperValue()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
SimulationState.TimeOutFrameCount = 10;

[UnityTest]
public IEnumerator AnnotationAsyncReportValue_ReportsProperJson()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensor = new RgbSensor();

[UnityTest]
public IEnumerator AnnotationAsyncReportResult_FindsCorrectPendingCaptureAfterStartingNewSequence()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var def = new TestDef();
DatasetCapture.Instance.RegisterAnnotationDefinition(def);

[Test]
public void CreateAnnotation_MultipleTimes_WritesProperTypeOnce()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var def1 = new TestDef();
var def2 = new TestDef();

[Test]
public void CreateAnnotation_MultipleTimesWithDifferentParameters_WritesProperTypes()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var def1 = new TestDef();
var def2 = new TestDef2();

12
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs


plane2.transform.localPosition = new Vector3(0, 0, 5);
yield return null;
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
DatasetCapture.Instance.ResetSimulation();

{
SimulationState.TimeOutFrameCount = 50;
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
SemanticSegmentationLabeler semanticSegmentationLabeler = null;
SetupCamera(pc =>

[UnityTest]
public IEnumerator Disabled_GeneratesCorrectDataset()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
SemanticSegmentationLabeler semanticSegmentationLabeler = null;
SetupCamera(pc =>

4
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs


[UnityTest]
public IEnumerator StartNewDatasetSequenceEveryIteration()
{
var collector = new CollectEndpoint();
DatasetCapture.SetEndpoint(collector);
var collector = ScriptableObject.CreateInstance<CollectEndpoint>();
DatasetCapture.Instance.OverrideEndpoint(collector);
var perceptionCamera = SetupPerceptionCamera();

99
com.unity.perception/Editor/GroundTruth/SettingsProvider.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Perception.Settings;
using UnityEngine.UIElements;
namespace UnityEditor.Perception.GroundTruth
{
public class PerceptionSettingsProvider : SettingsProvider
{
private SerializedObject m_CustomSettings;
public static string projectPath = "Project/Perception";
class Styles
{
public static GUIContent endpoint = new GUIContent("Active Endpoint");
}
public PerceptionSettingsProvider(string path, SettingsScope scope = SettingsScope.User)
: base(path, scope) { }
public override void OnActivate(string searchContext, VisualElement rootElement)
{
m_CustomSettings = PerceptionSettings.GetSerializedSettings();
}
public override void OnGUI(string searchContext)
{
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("endpoint"), Styles.endpoint);
m_CustomSettings.ApplyModifiedProperties();
}
[SettingsProvider]
public static SettingsProvider CreateMyCustomSettingsProvider()
{
if (PerceptionSettings.IsSettingsAvailable())
{
var provider = new PerceptionSettingsProvider(projectPath, SettingsScope.Project);
// Automatically extract all keywords from the Styles.
provider.keywords = GetSearchKeywordsFromGUIContentProperties<Styles>();
return provider;
}
// Settings Asset doesn't exist yet; no need to display anything in the Settings window.
return null;
}
}
static class PerceptionSettingsRegister
{
[SettingsProvider]
public static SettingsProvider CreatePerceptionSettingsProvider()
{
var provider = new SettingsProvider(PerceptionSettingsProvider.projectPath, SettingsScope.Project)
{
label = "Perception",
activateHandler = (searchContext, rootElement) =>
{
var settings = PerceptionSettings.GetSerializedSettings();
// rootElement is a VisualElement. If you add any children to it, the OnGUI function
// isn't called because the SettingsProvider uses the UIElements drawing framework.
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Packages/com.unity.perception/Editor/GroundTruth/Uss/Styles.uss");
rootElement.styleSheets.Add(styleSheet);
var title = new Label()
{
text = "Perception"
};
title.AddToClassList("title");
rootElement.Add(title);
var properties = new VisualElement()
{
style =
{
flexDirection = FlexDirection.Column
}
};
properties.AddToClassList("property-list");
rootElement.Add(properties);
var tf = new TextField()
{
value = settings.FindProperty("m_SomeString").stringValue
};
tf.AddToClassList("property-value");
properties.Add(tf);
},
keywords = new HashSet<string>(new[] { "Active Endpoint" })
};
return provider;
}
}
}

3
com.unity.perception/Editor/GroundTruth/SettingsProvider.cs.meta


fileFormatVersion: 2
guid: 987301ba33874109b5562048bc3d5956
timeCreated: 1634067424

3
com.unity.perception/Runtime/Settings.meta


fileFormatVersion: 2
guid: a26f91b2e24a4a5d90008ca1851054bd
timeCreated: 1634074669

40
com.unity.perception/Runtime/Settings/PerceptionSettings.cs


using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEngine.Perception.Settings
{
public class PerceptionSettings : ScriptableObject
{
const string k_SettingsPath = "Assets/Settings/PerceptionSettings.asset";
[SerializeField]
ConsumerEndpoint endpoint;
public static ConsumerEndpoint Endpoint => GetOrCreateSettings().endpoint;
static PerceptionSettings GetOrCreateSettings()
{
var settings = AssetDatabase.LoadAssetAtPath<PerceptionSettings>(k_SettingsPath);
if (settings == null)
{
settings = ScriptableObject.CreateInstance<PerceptionSettings>();
settings.endpoint = null;
AssetDatabase.CreateAsset(settings, k_SettingsPath);
AssetDatabase.SaveAssets();
}
return settings;
}
public static bool IsSettingsAvailable()
{
return File.Exists(PerceptionSettings.k_SettingsPath);
}
public static SerializedObject GetSerializedSettings()
{
return new SerializedObject(GetOrCreateSettings());
}
}
}

11
com.unity.perception/Runtime/Settings/PerceptionSettings.cs.meta


fileFormatVersion: 2
guid: c5ee903ff896bde4bb82aed4aec2bf61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存