浏览代码

some changes to make runtime labeling and label config work

/addressables-test
Mohsen Kamalzadeh 4 年前
当前提交
5aaf5f94
共有 4 个文件被更改,包括 120 次插入5 次删除
  1. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  2. 8
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelManager.cs
  3. 4
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  4. 111
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs

2
com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs


if (visualizationEnabled) OnVisualize();
}
internal void Init(PerceptionCamera newPerceptionCamera)
public void Init(PerceptionCamera newPerceptionCamera)
{
try
{

8
com.unity.perception/Runtime/GroundTruth/Labeling/LabelManager.cs


/// </summary>
public IEnumerable<Labeling> registeredLabels => m_RegisteredLabels;
public List<string> LabelStringsForAutoLabelConfig { get; } = new List<string>();
public void AddLabelStringToAutoLabelConfigList(string label)
{
if(!LabelStringsForAutoLabelConfig.Contains(label))
LabelStringsForAutoLabelConfig.Add(label);
}
/// <summary>
/// Registers all pending labels.
/// Called once per frame during LateUpdate by the <see cref="PerceptionUpdater"/>.

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


continue;
if (!labeler.isInitialized)
labeler.Init(this);
continue;
labeler.InternalOnUpdate();
}

continue;
if (!labeler.isInitialized)
labeler.Init(this);
continue;
action(labeler);
}

111
com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs


using System;
using System.Collections.Generic;
using UnityEngine.Perception.Randomization.Parameters;
using UnityEngine.Perception.Randomization.Samplers;
namespace UnityEngine.Perception.Randomization.Scenarios
{

}
/// <inheritdoc/>
protected override void OnIterationStart()
protected override void OnUpdate()
if (m_PerceptionCamera != null && currentIterationFrame == constants.framesPerIteration - 1)
if (m_PerceptionCamera && currentIterationFrame == constants.framesPerIteration - 1
&& currentIteration > 1)
{
//skip first iteration for capturing because labelers are not yet initialized. They are currently initialized at the end of the first iteration.
//TO DO: Make scheduling more robust in order to capture first iteration too
}
}
protected override void OnIterationEnd()
{
if (currentIteration == constants.instanceCount + 1)
{
//it is the penultimate frame of the first iteration, so all placement randomizers have woken up and labeled their prefabs by now
SetupLabelConfigs();
}
}
static void SetupLabelConfigs()
{
var perceptionCamera = FindObjectOfType<PerceptionCamera>();
var idLabelConfig = ScriptableObject.CreateInstance<IdLabelConfig>();
idLabelConfig.autoAssignIds = true;
idLabelConfig.startingLabelId = StartingLabelId.One;
var stringList = LabelManager.singleton.LabelStringsForAutoLabelConfig;
var idLabelEntries = new List<IdLabelEntry>();
for (var i = 0; i < stringList.Count; i++)
{
idLabelEntries.Add(new IdLabelEntry
{
id = i,
label = stringList[i]
});
}
idLabelConfig.Init(idLabelEntries);
var semanticLabelConfig = ScriptableObject.CreateInstance<SemanticSegmentationLabelConfig>();
var semanticLabelEntries = new List<SemanticSegmentationLabelEntry>();
for (var i = 0; i < stringList.Count; i++)
{
semanticLabelEntries.Add(new SemanticSegmentationLabelEntry()
{
label = stringList[i],
color = GetUniqueSemanticSegmentationColor()
});
}
semanticLabelConfig.Init(semanticLabelEntries);
foreach (var labeler in perceptionCamera.labelers)
{
if (!labeler.enabled)
continue;
switch (labeler)
{
case BoundingBox2DLabeler boundingBox2DLabeler:
boundingBox2DLabeler.idLabelConfig = idLabelConfig;
break;
case BoundingBox3DLabeler boundingBox3DLabeler:
boundingBox3DLabeler.idLabelConfig = idLabelConfig;
break;
case ObjectCountLabeler objectCountLabeler:
objectCountLabeler.labelConfig.autoAssignIds = idLabelConfig.autoAssignIds;
objectCountLabeler.labelConfig.startingLabelId = idLabelConfig.startingLabelId;
objectCountLabeler.labelConfig.Init(idLabelEntries);
break;
case RenderedObjectInfoLabeler renderedObjectInfoLabeler:
renderedObjectInfoLabeler.idLabelConfig = idLabelConfig;
break;
case KeypointLabeler keypointLabeler:
keypointLabeler.idLabelConfig = idLabelConfig;
break;
case InstanceSegmentationLabeler instanceSegmentationLabeler:
instanceSegmentationLabeler.idLabelConfig = idLabelConfig;
break;
case SemanticSegmentationLabeler semanticSegmentationLabeler:
semanticSegmentationLabeler.labelConfig = semanticLabelConfig;
break;
}
labeler.Init(perceptionCamera);
}
}
static HashSet<Color> s_ColorsAlreadyUsed = new HashSet<Color>();
static ColorRgbParameter s_SemanticColorParameter = new ColorRgbParameter();
static Color GetUniqueSemanticSegmentationColor()
{
var seed = SamplerState.NextRandomState();
var sampledColor = s_SemanticColorParameter.Sample();
var maxTries = 1000;
var count = 0;
while (s_ColorsAlreadyUsed.Contains(sampledColor) && count <= maxTries)
{
count++;
sampledColor = s_SemanticColorParameter.Sample();
Debug.LogError("Failed to find unique semantic segmentation color for a label.");
}
s_ColorsAlreadyUsed.Add(sampledColor);
return sampledColor;
}
}
}
正在加载...
取消
保存