浏览代码

Updating to use LabelEntry ids.

/main
Jon Hogins 4 年前
当前提交
923061f2
共有 3 个文件被更改,包括 32 次插入15 次删除
  1. 17
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
  2. 10
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  3. 20
      com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs

17
com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs


/// <returns>Returns true if a match was found. False if not.</returns>
public bool TryGetMatchingConfigurationEntry(Labeling labeling, out LabelEntry labelEntry)
{
return TryGetMatchingConfigurationEntry(labeling, out labelEntry, out int _);
}
/// <summary>
/// Attempts to find the matching index in <see cref="LabelEntries"/> for the given <see cref="Labeling"/>.
/// </summary>
/// <remarks>
/// The matching index is the first class name in the given Labeling which matches an entry in <see cref="LabelEntries"/>.
/// </remarks>
/// <param name="labeling">The <see cref="Labeling"/> to match </param>
/// <param name="labelEntry">When this method returns, contains the matching <see cref="LabelEntry"/>, or <code>default</code> if no match was found.</param>
/// <param name="labelEntryIndex">When this method returns, contains the index of the matching <see cref="LabelEntry"/>, or <code>-1</code> if no match was found.</param>
/// <returns>Returns true if a match was found. False if not.</returns>
public bool TryGetMatchingConfigurationEntry(Labeling labeling, out LabelEntry labelEntry, out int labelEntryIndex)
{
foreach (var labelingClass in labeling.labels)
{
for (var i = 0; i < LabelEntries.Count; i++)

{
labelEntry = entry;
labelEntryIndex = i;
labelEntryIndex = -1;
labelEntry = default;
return false;
}

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


if (produceSegmentationImages)
{
var specs = LabelingConfiguration.LabelEntries.Select((l, index) => new SemanticSegmentationSpec()
var specs = LabelingConfiguration.LabelEntries.Select((l) => new SemanticSegmentationSpec()
label_id = index,
label_id = l.id,
label_name = l.label,
pixel_value = l.value
}).ToArray();

if (produceObjectCountAnnotations || produceBoundingBoxAnnotations || produceRenderedObjectInfoMetric)
{
var labelingMetricSpec = LabelingConfiguration.LabelEntries.Select((l, index) => new ObjectCountSpec()
var labelingMetricSpec = LabelingConfiguration.LabelEntries.Select((l) => new ObjectCountSpec()
label_id = index,
label_id = l.id,
label_name = l.label,
}).ToArray();

{
m_ClassCountValues[i] = new ClassCountValue()
{
label_id = i,
label_id = entries[i].id,
label_name = entries[i].label,
count = counts[i]
};

20
com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs


}
}
NativeList<int> m_InstanceIdToClassIdLookup;
NativeList<int> m_InstanceIdToLabelEntryIndexLookup;
LabelingConfiguration m_LabelingConfiguration;
// ReSharper disable once InvalidXmlDocComment

public RenderedObjectInfoGenerator(LabelingConfiguration labelingConfiguration)
{
m_LabelingConfiguration = labelingConfiguration;
m_InstanceIdToClassIdLookup = new NativeList<int>(k_StartingObjectCount, Allocator.Persistent);
m_InstanceIdToLabelEntryIndexLookup = new NativeList<int>(k_StartingObjectCount, Allocator.Persistent);
}
/// <inheritdoc/>

{
if (m_InstanceIdToClassIdLookup.Length <= instanceId)
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
m_InstanceIdToClassIdLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
m_InstanceIdToClassIdLookup[(int)instanceId] = entry.id;
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = entry.id;
}
}

for (var i = 0; i < keyValueArrays.Keys.Length; i++)
{
var instanceId = keyValueArrays.Keys[i];
if (m_InstanceIdToClassIdLookup.Length <= instanceId)
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
var classId = m_InstanceIdToClassIdLookup[instanceId];
var classId = m_InstanceIdToLabelEntryIndexLookup[instanceId];
classCounts[classId]++;
var renderedObjectInfo = keyValueArrays.Values[i];
var boundingBox = renderedObjectInfo.boundingBox;

public bool TryGetLabelIdFromInstanceId(int instanceId, out int labelId)
{
labelId = -1;
if (m_InstanceIdToClassIdLookup.Length <= instanceId)
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
labelId = m_InstanceIdToClassIdLookup[instanceId];
labelId = m_InstanceIdToLabelEntryIndexLookup[instanceId];
return true;
}

m_InstanceIdToClassIdLookup.Dispose();
m_InstanceIdToLabelEntryIndexLookup.Dispose();
}
}
}
正在加载...
取消
保存