浏览代码

removed label config setup logic from fixed length scenario

/addressables-test
Mohsen Kamalzadeh 4 年前
当前提交
7600c8fe
共有 1 个文件被更改,包括 1 次插入102 次删除
  1. 103
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs

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


[AddComponentMenu("Perception/Scenarios/Fixed Length Scenario")]
public class FixedLengthScenario: UnitySimulationScenario<FixedLengthScenario.Constants>
{
PerceptionCamera m_PerceptionCamera;
protected PerceptionCamera m_PerceptionCamera;
/// <summary>
/// Constants describing the execution of this scenario

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;
}
}
}
正在加载...
取消
保存