浏览代码
Major refactoring. Moving RenderedObjectInfo and instance segmentation back into PerceptionCamera. Moving instance id -> labelentry cache into LabelingConfiguration. Properly implementing the labelers.
Major refactoring. Moving RenderedObjectInfo and instance segmentation back into PerceptionCamera. Moving instance id -> labelentry cache into LabelingConfiguration. Properly implementing the labelers.
Still need to implement the hookups in PerceptionCamera to call into the labelers at runtime and write more tests./labeler_mock_mb
Jon Hogins
4 年前
当前提交
88c3dc1a
共有 30 个文件被更改,包括 631 次插入 和 643 次删除
-
119TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
-
6TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset
-
36com.unity.perception/Editor/GroundTruth/BoundingBoxLabelerEditor.cs
-
5com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs
-
23com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
-
153com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
-
49com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs
-
45com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
-
30com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
9com.unity.perception/Runtime/GroundTruth/PerceptionCamera_InstanceSegmentation.cs
-
13com.unity.perception/Runtime/GroundTruth/RenderedObjectInfo.cs
-
77com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
-
12com.unity.perception/Runtime/GroundTruth/SemanticSegmentationCrossPipelinePass.cs
-
5com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs
-
29com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
-
50com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
-
22com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountLabelerTests.cs
-
26com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
-
3com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs.meta
-
112com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
-
3com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs.meta
-
54com.unity.perception/Runtime/GroundTruth/Labeling/LabelEntryMatchCache.cs
-
3com.unity.perception/Runtime/GroundTruth/Labeling/LabelEntryMatchCache.cs.meta
-
162com.unity.perception/Tests/Runtime/GroundTruthTests/RenderedObjectInfoTests.cs
-
11com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs.meta
-
25com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs
-
192com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs
-
0/com.unity.perception/Tests/Runtime/GroundTruthTests/RenderedObjectInfoTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountLabelerTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountLabelerTests.cs
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
[Serializable] |
|||
public abstract class CameraLabeler |
|||
{ |
|||
public bool enabled; |
|||
public bool foldout; |
|||
|
|||
protected PerceptionCamera PerceptionCamera { get; private set; } |
|||
protected SensorHandle SensorHandle { get; private set; } |
|||
|
|||
public abstract void Setup(); |
|||
public virtual void OnUpdate() {} |
|||
public virtual void OnBeginRendering() {} |
|||
|
|||
public virtual void OnSimulationEnding() {} |
|||
|
|||
internal void Init(PerceptionCamera perceptionCamera) |
|||
{ |
|||
PerceptionCamera = perceptionCamera; |
|||
SensorHandle = perceptionCamera.SensorHandle; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1f21ae5ed3374b7288ad9bd4ad367c59 |
|||
timeCreated: 1593188098 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Diagnostics.CodeAnalysis; |
|||
using Unity.Collections; |
|||
using Unity.Profiling; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
[Serializable] |
|||
public class ObjectCountLabeler : CameraLabeler |
|||
{ |
|||
/// <summary>
|
|||
/// The ID to use for object count annotations in the resulting dataset
|
|||
/// </summary>
|
|||
public string objectCountMetricId = "51DA3C27-369D-4929-AEA6-D01614635CE2"; |
|||
|
|||
public LabelingConfiguration labelingConfiguration => m_LabelingConfiguration; |
|||
|
|||
/// <summary>
|
|||
/// Fired when the object counts are computed for a frame.
|
|||
/// </summary>
|
|||
public event Action<int, NativeSlice<uint>,IReadOnlyList<LabelEntry>> ObjectCountsComputed; |
|||
|
|||
[SerializeField] |
|||
LabelingConfiguration m_LabelingConfiguration; |
|||
|
|||
static ProfilerMarker s_ClassCountCallback = new ProfilerMarker("OnClassLabelsReceived"); |
|||
|
|||
ClassCountValue[] m_ClassCountValues; |
|||
|
|||
Dictionary<int, AsyncMetric> m_ObjectCountAsyncMetrics = new Dictionary<int, AsyncMetric>(); |
|||
MetricDefinition m_ObjectCountMetricDefinition; |
|||
|
|||
public ObjectCountLabeler() |
|||
{ |
|||
} |
|||
public ObjectCountLabeler(LabelingConfiguration labelingConfiguration) |
|||
{ |
|||
this.m_LabelingConfiguration = labelingConfiguration; |
|||
} |
|||
|
|||
[SuppressMessage("ReSharper", "InconsistentNaming")] |
|||
[SuppressMessage("ReSharper", "NotAccessedField.Local")] |
|||
struct ClassCountValue |
|||
{ |
|||
public int label_id; |
|||
public string label_name; |
|||
public uint count; |
|||
} |
|||
|
|||
public override void Setup() |
|||
{ |
|||
PerceptionCamera.RenderedObjectInfosCalculated += (frameCount, objectInfo) => |
|||
{ |
|||
NativeArray<uint> objectCounts = ComputeObjectCounts(objectInfo); |
|||
ObjectCountsComputed?.Invoke(frameCount, objectCounts, labelingConfiguration.LabelEntries); |
|||
ProduceObjectCountMetric(objectCounts, m_LabelingConfiguration.LabelEntries, frameCount); |
|||
}; |
|||
} |
|||
|
|||
public override void OnBeginRendering() |
|||
{ |
|||
if (m_ObjectCountMetricDefinition.Equals(default)) |
|||
{ |
|||
m_ObjectCountMetricDefinition = SimulationManager.RegisterMetricDefinition("object count", m_LabelingConfiguration.GetAnnotationSpecification(), |
|||
"Counts of objects for each label in the sensor's view", id: new Guid(objectCountMetricId)); |
|||
} |
|||
|
|||
m_ObjectCountAsyncMetrics[Time.frameCount] = PerceptionCamera.SensorHandle.ReportMetricAsync(m_ObjectCountMetricDefinition); |
|||
} |
|||
|
|||
NativeArray<uint> ComputeObjectCounts(NativeArray<RenderedObjectInfo> objectInfo) |
|||
{ |
|||
var objectCounts = new NativeArray<uint>(m_LabelingConfiguration.LabelEntries.Count, Allocator.Temp); |
|||
foreach (var info in objectInfo) |
|||
{ |
|||
if (!m_LabelingConfiguration.TryGetLabelEntryFromInstanceId(info.instanceId, out _, out var labelIndex)) |
|||
continue; |
|||
|
|||
objectCounts[labelIndex]++; |
|||
} |
|||
|
|||
return objectCounts; |
|||
} |
|||
|
|||
void ProduceObjectCountMetric(NativeSlice<uint> counts, IReadOnlyList<LabelEntry> entries, int frameCount) |
|||
{ |
|||
using (s_ClassCountCallback.Auto()) |
|||
{ |
|||
if (!m_ObjectCountAsyncMetrics.TryGetValue(frameCount, out var classCountAsyncMetric)) |
|||
return; |
|||
|
|||
m_ObjectCountAsyncMetrics.Remove(frameCount); |
|||
|
|||
if (m_ClassCountValues == null || m_ClassCountValues.Length != entries.Count) |
|||
m_ClassCountValues = new ClassCountValue[entries.Count]; |
|||
|
|||
for (var i = 0; i < entries.Count; i++) |
|||
{ |
|||
m_ClassCountValues[i] = new ClassCountValue() |
|||
{ |
|||
label_id = entries[i].id, |
|||
label_name = entries[i].label, |
|||
count = counts[i] |
|||
}; |
|||
} |
|||
|
|||
classCountAsyncMetric.ReportValues(m_ClassCountValues); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 715672f8c1f94106b6e84431e53c6096 |
|||
timeCreated: 1593183448 |
|
|||
using System; |
|||
using Unity.Collections; |
|||
using Unity.Entities; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Cache of instance id -> label entry index for a LabelConfig. This is not well optimized and is the source of a known memory leak for apps that create new instances frequently
|
|||
/// </summary>
|
|||
class LabelEntryMatchCache : IGroundTruthGenerator, IDisposable |
|||
{ |
|||
const int k_StartingObjectCount = 1 << 8; |
|||
NativeList<ushort> m_InstanceIdToLabelEntryIndexLookup; |
|||
LabelingConfiguration m_LabelingConfiguration; |
|||
|
|||
public LabelEntryMatchCache(LabelingConfiguration labelingConfiguration) |
|||
{ |
|||
m_LabelingConfiguration = labelingConfiguration; |
|||
World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<GroundTruthLabelSetupSystem>().Activate(this); |
|||
m_InstanceIdToLabelEntryIndexLookup = new NativeList<ushort>(k_StartingObjectCount, Allocator.Persistent); |
|||
} |
|||
|
|||
public bool TryGetLabelEntryFromInstanceId(uint instanceId, out LabelEntry labelEntry, out int index) |
|||
{ |
|||
labelEntry = default; |
|||
index = -1; |
|||
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId) |
|||
return false; |
|||
|
|||
index = m_InstanceIdToLabelEntryIndexLookup[(int)instanceId]; |
|||
labelEntry = m_LabelingConfiguration.LabelEntries[index]; |
|||
return true; |
|||
} |
|||
|
|||
void IGroundTruthGenerator.SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId) |
|||
{ |
|||
if (m_LabelingConfiguration.TryGetMatchingConfigurationEntry(labeling, out _, out var index)) |
|||
{ |
|||
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId) |
|||
{ |
|||
m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory); |
|||
} |
|||
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = (ushort)index; |
|||
} |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<GroundTruthLabelSetupSystem>().Deactivate(this); |
|||
m_InstanceIdToLabelEntryIndexLookup.Dispose(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e736a5078e0a44d69bdc643b3157f670 |
|||
timeCreated: 1593182152 |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using NUnit.Framework; |
|||
using Unity.Collections; |
|||
using Unity.Entities; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.GroundTruth; |
|||
using UnityEngine.TestTools; |
|||
|
|||
namespace GroundTruthTests |
|||
{ |
|||
[TestFixture] |
|||
public class RenderedObjectInfoTests : GroundTruthTestBase |
|||
{ |
|||
public class ProducesCorrectObjectInfoData |
|||
{ |
|||
public RenderedObjectInfo[] renderedObjectInfosExpected; |
|||
public uint[] data; |
|||
public BoundingBoxOrigin boundingBoxOrigin; |
|||
public int stride; |
|||
public string name; |
|||
public ProducesCorrectObjectInfoData(uint[] data, RenderedObjectInfo[] renderedObjectInfosExpected, int stride, BoundingBoxOrigin boundingBoxOrigin, string name) |
|||
{ |
|||
this.data = data; |
|||
this.renderedObjectInfosExpected = renderedObjectInfosExpected; |
|||
this.stride = stride; |
|||
this.name = name; |
|||
this.boundingBoxOrigin = boundingBoxOrigin; |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return name; |
|||
} |
|||
} |
|||
public static IEnumerable ProducesCorrectBoundingBoxesTestCases() |
|||
{ |
|||
yield return new ProducesCorrectObjectInfoData( |
|||
new uint[] |
|||
{ |
|||
1, 1, |
|||
1, 1 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(0, 0, 2, 2), |
|||
instanceId = 1, |
|||
pixelCount = 4 |
|||
} |
|||
}, |
|||
2, |
|||
BoundingBoxOrigin.BottomLeft, |
|||
"SimpleBox"); |
|||
yield return new ProducesCorrectObjectInfoData( |
|||
new uint[] |
|||
{ |
|||
1, 0, 2, |
|||
1, 0, 0 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(0, 0, 1, 2), |
|||
instanceId = 1, |
|||
pixelCount = 2 |
|||
}, |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(2, 0, 1, 1), |
|||
instanceId = 2, |
|||
pixelCount = 1 |
|||
} |
|||
}, |
|||
3, |
|||
BoundingBoxOrigin.BottomLeft, |
|||
"WithGaps"); |
|||
yield return new ProducesCorrectObjectInfoData( |
|||
new uint[] |
|||
{ |
|||
1, 2, 1, |
|||
1, 2, 1 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(0, 0, 3, 2), |
|||
instanceId = 1, |
|||
pixelCount = 4 |
|||
}, |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(1, 0, 1, 2), |
|||
instanceId = 2, |
|||
pixelCount = 2 |
|||
} |
|||
}, |
|||
3, |
|||
BoundingBoxOrigin.BottomLeft, |
|||
"Interleaved"); |
|||
yield return new ProducesCorrectObjectInfoData( |
|||
new uint[] |
|||
{ |
|||
0, 0, |
|||
0, 0, |
|||
0, 1 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(1, 0, 1, 1), |
|||
instanceId = 1, |
|||
pixelCount = 1 |
|||
}, |
|||
}, |
|||
2, |
|||
BoundingBoxOrigin.TopLeft, |
|||
"TopLeft"); |
|||
} |
|||
|
|||
[UnityTest] |
|||
public IEnumerator ProducesCorrectBoundingBoxes([ValueSource(nameof(ProducesCorrectBoundingBoxesTestCases))] ProducesCorrectObjectInfoData producesCorrectObjectInfoData) |
|||
{ |
|||
var label = "label"; |
|||
var label2 = "label2"; |
|||
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>(); |
|||
|
|||
labelingConfiguration.Init(new List<LabelEntry> |
|||
{ |
|||
new LabelEntry |
|||
{ |
|||
id = 1, |
|||
label = label, |
|||
value = 500 |
|||
}, |
|||
new LabelEntry |
|||
{ |
|||
id = 2, |
|||
label = label2, |
|||
value = 500 |
|||
} |
|||
}); |
|||
|
|||
var renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(); |
|||
|
|||
//Put a plane in front of the camera
|
|||
AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label)); |
|||
AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label2)); |
|||
yield return null; |
|||
|
|||
var dataNativeArray = new NativeArray<uint>(producesCorrectObjectInfoData.data, Allocator.Persistent); |
|||
|
|||
renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectObjectInfoData.stride, producesCorrectObjectInfoData.boundingBoxOrigin, out var boundingBoxes, Allocator.Temp); |
|||
|
|||
CollectionAssert.AreEqual(producesCorrectObjectInfoData.renderedObjectInfosExpected, boundingBoxes.ToArray()); |
|||
|
|||
dataNativeArray.Dispose(); |
|||
boundingBoxes.Dispose(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 43085b9d882c415b90fb9ebe4d765f26 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.Collections; |
|||
using UnityEngine.Experimental.Rendering; |
|||
#if HDRP_PRESENT
|
|||
using UnityEngine.Rendering.HighDefinition; |
|||
#endif
|
|||
|
|||
namespace UnityEngine.Perception.GroundTruth { |
|||
// public class InstanceSegmentationLabeler : CameraLabeler
|
|||
// {
|
|||
// //Uncomment when we support saving instance segmentation labels
|
|||
// //public bool saveImages = false;
|
|||
// //public string annotationId = "E657461D-B950-42E1-8141-BEC9B4810241";
|
|||
//
|
|||
// public override void Setup()
|
|||
// {
|
|||
// PerceptionCamera.InstanceSegmentationImageReadback += OnInstanceSegmentationImageReadback;
|
|||
// }
|
|||
//
|
|||
// void OnInstanceSegmentationImageReadback(int frameCount, NativeArray<uint> imageData, RenderTexture renderTexture)
|
|||
// {
|
|||
// throw new NotImplementedException();
|
|||
// }
|
|||
// }
|
|||
} |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using NUnit.Framework; |
|||
using Unity.Collections; |
|||
using Unity.Entities; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.GroundTruth; |
|||
using UnityEngine.TestTools; |
|||
|
|||
namespace GroundTruthTests |
|||
{ |
|||
[TestFixture] |
|||
public class BoundingBox2DTests : GroundTruthTestBase |
|||
{ |
|||
public class ProducesCorrectBoundingBoxesData |
|||
{ |
|||
public uint[] classCountsExpected; |
|||
public RenderedObjectInfo[] boundingBoxesExpected; |
|||
public uint[] data; |
|||
public BoundingBoxOrigin boundingBoxOrigin; |
|||
public int stride; |
|||
public string name; |
|||
public ProducesCorrectBoundingBoxesData(uint[] data, RenderedObjectInfo[] boundingBoxesExpected, uint[] classCountsExpected, int stride, BoundingBoxOrigin boundingBoxOrigin, string name) |
|||
{ |
|||
this.data = data; |
|||
this.boundingBoxesExpected = boundingBoxesExpected; |
|||
this.classCountsExpected = classCountsExpected; |
|||
this.stride = stride; |
|||
this.name = name; |
|||
this.boundingBoxOrigin = boundingBoxOrigin; |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return name; |
|||
} |
|||
} |
|||
public static IEnumerable ProducesCorrectBoundingBoxesTestCases() |
|||
{ |
|||
yield return new ProducesCorrectBoundingBoxesData( |
|||
new uint[] |
|||
{ |
|||
1, 1, |
|||
1, 1 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(0, 0, 2, 2), |
|||
instanceId = 1, |
|||
labelId = 1, |
|||
pixelCount = 4 |
|||
} |
|||
}, new uint[] |
|||
{ |
|||
1, |
|||
0 |
|||
}, |
|||
2, |
|||
BoundingBoxOrigin.BottomLeft, |
|||
"SimpleBox"); |
|||
yield return new ProducesCorrectBoundingBoxesData( |
|||
new uint[] |
|||
{ |
|||
1, 0, 2, |
|||
1, 0, 0 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(0, 0, 1, 2), |
|||
instanceId = 1, |
|||
labelId = 1, |
|||
pixelCount = 2 |
|||
}, |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(2, 0, 1, 1), |
|||
instanceId = 2, |
|||
labelId = 2, |
|||
pixelCount = 1 |
|||
} |
|||
}, new uint[] |
|||
{ |
|||
1, |
|||
1 |
|||
}, |
|||
3, |
|||
BoundingBoxOrigin.BottomLeft, |
|||
"WithGaps"); |
|||
yield return new ProducesCorrectBoundingBoxesData( |
|||
new uint[] |
|||
{ |
|||
1, 2, 1, |
|||
1, 2, 1 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(0, 0, 3, 2), |
|||
instanceId = 1, |
|||
labelId = 1, |
|||
pixelCount = 4 |
|||
}, |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(1, 0, 1, 2), |
|||
instanceId = 2, |
|||
labelId = 2, |
|||
pixelCount = 2 |
|||
} |
|||
}, new uint[] |
|||
{ |
|||
1, |
|||
1 |
|||
}, |
|||
3, |
|||
BoundingBoxOrigin.BottomLeft, |
|||
"Interleaved"); |
|||
yield return new ProducesCorrectBoundingBoxesData( |
|||
new uint[] |
|||
{ |
|||
0, 0, |
|||
0, 0, |
|||
0, 1 |
|||
}, new[] |
|||
{ |
|||
new RenderedObjectInfo() |
|||
{ |
|||
boundingBox = new Rect(1, 0, 1, 1), |
|||
instanceId = 1, |
|||
labelId = 1, |
|||
pixelCount = 1 |
|||
}, |
|||
}, new uint[] |
|||
{ |
|||
1, |
|||
0 |
|||
}, |
|||
2, |
|||
BoundingBoxOrigin.TopLeft, |
|||
"TopLeft"); |
|||
} |
|||
|
|||
[UnityTest] |
|||
public IEnumerator ProducesCorrectBoundingBoxes([ValueSource(nameof(ProducesCorrectBoundingBoxesTestCases))] ProducesCorrectBoundingBoxesData producesCorrectBoundingBoxesData) |
|||
{ |
|||
var label = "label"; |
|||
var label2 = "label2"; |
|||
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>(); |
|||
|
|||
labelingConfiguration.LabelEntries = new List<LabelEntry> |
|||
{ |
|||
new LabelEntry |
|||
{ |
|||
id = 1, |
|||
label = label, |
|||
value = 500 |
|||
}, |
|||
new LabelEntry |
|||
{ |
|||
id = 2, |
|||
label = label2, |
|||
value = 500 |
|||
} |
|||
}; |
|||
|
|||
var renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(labelingConfiguration); |
|||
var groundTruthLabelSetupSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem<GroundTruthLabelSetupSystem>(); |
|||
groundTruthLabelSetupSystem.Activate(renderedObjectInfoGenerator); |
|||
|
|||
//Put a plane in front of the camera
|
|||
AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label)); |
|||
AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label2)); |
|||
yield return null; |
|||
|
|||
var dataNativeArray = new NativeArray<uint>(producesCorrectBoundingBoxesData.data, Allocator.Persistent); |
|||
|
|||
renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectBoundingBoxesData.stride, producesCorrectBoundingBoxesData.boundingBoxOrigin, out var boundingBoxes, out var classCounts, Allocator.Temp); |
|||
|
|||
CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.boundingBoxesExpected, boundingBoxes.ToArray()); |
|||
CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.classCountsExpected, classCounts.ToArray()); |
|||
|
|||
dataNativeArray.Dispose(); |
|||
boundingBoxes.Dispose(); |
|||
classCounts.Dispose(); |
|||
groundTruthLabelSetupSystem.Deactivate(renderedObjectInfoGenerator); |
|||
renderedObjectInfoGenerator.Dispose(); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue