浏览代码

Simplifying id auto assignment by letting the user select between 0 and 1-based labels.

/main
Jon Hogins 5 年前
当前提交
c50b0293
共有 4 个文件被更改,包括 43 次插入22 次删除
  1. 36
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs
  2. 7
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
  3. 19
      com.unity.perception/Runtime/GroundTruth/Labeling/StartingLabelId.cs
  4. 3
      com.unity.perception/Runtime/GroundTruth/Labeling/StartingLabelId.cs.meta

36
com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs


if (!autoAssign)
return;
var newFirstElement = list.serializedProperty.GetArrayElementAtIndex(0);
if (newIndex == 0 && list.serializedProperty.arraySize > 1)
{
var oldFirstId = list.serializedProperty.GetArrayElementAtIndex(1).FindPropertyRelative(nameof(LabelEntry.id)).intValue;
newFirstElement.FindPropertyRelative(nameof(LabelEntry.id)).intValue = oldFirstId;
}
if (oldIndex == 0)
{
var oldFirstId = list.serializedProperty.GetArrayElementAtIndex(newIndex).FindPropertyRelative(nameof(LabelEntry.id)).intValue;
newFirstElement.FindPropertyRelative(nameof(LabelEntry.id)).intValue = oldFirstId;
}
AutoAssignIds();
}

using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position, new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
using (new EditorGUI.DisabledScope(autoAssign && index != 0))
using (new EditorGUI.DisabledScope(autoAssign))
{
var newLabel = EditorGUI.IntField(contentRect, nameof(LabelEntry.id), idProperty.intValue);
if (change.changed)

public override void OnInspectorGUI()
{
serializedObject.Update();
var autoAssignIdsProperty = serializedObject.FindProperty(nameof(LabelingConfiguration.AutoAssignIds));
var autoAssignIdsProperty = serializedObject.FindProperty(nameof(LabelingConfiguration.AutoAssignIds));
AutoAssignIds();
}
if (autoAssignIdsProperty.boolValue)
{
using (var change = new EditorGUI.ChangeCheckScope())
var ok = EditorUtility.DisplayDialog("Enable auto-assigned labels", "Existing label ids will be overwritten. Enable label auto-assignment?", "Yes", "Cancel");
if (ok)
{
var startingLabelIdProperty = serializedObject.FindProperty(nameof(LabelingConfiguration.StartingLabelId));
EditorGUILayout.PropertyField(startingLabelIdProperty);
if (change.changed)
}
else
autoAssignIdsProperty.boolValue = false;
}
}

if (size == 0)
return;
var nextId = serializedProperty.GetArrayElementAtIndex(0).FindPropertyRelative(nameof(LabelEntry.id)).intValue + 1;
for (int i = 1; i < size; i++)
var startingLabelId = (StartingLabelId)serializedObject.FindProperty(nameof(LabelingConfiguration.StartingLabelId)).enumValueIndex;
var nextId = startingLabelId == StartingLabelId.One ? 1 : 0;
for (int i = 0; i < size; i++)
{
serializedProperty.GetArrayElementAtIndex(i).FindPropertyRelative(nameof(LabelEntry.id)).intValue = nextId;
nextId++;

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


public class LabelingConfiguration : ScriptableObject
{
/// <summary>
/// Whether the inspector will auto-assign ids based on the id of the first element
/// Whether the inspector will auto-assign ids based on the id of the first element.
/// <summary>
/// Whether the inspector will start label ids at zero or one when <see cref="AutoAssignIds"/> is enabled.
/// </summary>
public StartingLabelId StartingLabelId = StartingLabelId.One;
/// <summary>
/// A sequence of <see cref="LabelEntry"/> which defines the labels relevant for this configuration and their values.

19
com.unity.perception/Runtime/GroundTruth/Labeling/StartingLabelId.cs


using System;
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Selector for whether label ids should start at zero or one. <seealso cref="LabelingConfiguration.StartingLabelId"/>.
/// </summary>
public enum StartingLabelId
{
/// <summary>
/// Start label id assignment at 0
/// </summary>
Zero,
/// <summary>
/// Start label id assignment at 1
/// </summary>
One
}
}

3
com.unity.perception/Runtime/GroundTruth/Labeling/StartingLabelId.cs.meta


fileFormatVersion: 2
guid: 2f8f1d8ca6304fab94bf1c45c9ad0873
timeCreated: 1589210485
正在加载...
取消
保存