浏览代码

Attempt at a combined labelingconfiguration. Overly complex I think.

/labeler_mock_mb
Jon Hogins 4 年前
当前提交
92843a4f
共有 5 个文件被更改,包括 145 次插入2 次删除
  1. 6
      com.unity.perception/Editor/Unity.Perception.Editor.asmdef
  2. 33
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs
  3. 3
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs.meta
  4. 102
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs
  5. 3
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs.meta

6
com.unity.perception/Editor/Unity.Perception.Editor.asmdef


],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [

33
com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs


using System.IO;
using Newtonsoft.Json.Linq;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth
{
[ScriptedImporter(1, "labelconfig")]
public class LabelingConfigurationImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
var text = File.ReadAllText(ctx.assetPath);
var jObject = JObject.Parse(text);
var config = ScriptableObject.CreateInstance<LabelingConfiguration>();
if (jObject["auto-assign-ids"].HasValues)
config.AutoAssignIds = jObject["auto-assign-ids"].Value<bool>();
if (jObject["starting-index"].HasValues)
{
var startingLabelId = (StartingLabelId)jObject["starting-index"].Value<int>();
config.StartingLabelId = startingLabelId;
}
if (jObject["configs"].HasValues)
{
}
ctx.SetMainObject(config);
}
}
}

3
com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs.meta


fileFormatVersion: 2
guid: b0ecdacff7b34c54b2bad5b04e868356
timeCreated: 1589474006

102
com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs


using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// A definition for how a <see cref="Labeling"/> should be resolved to a single label and id for ground truth generation.
/// </summary>
[CreateAssetMenu(fileName = "LabelingConfiguration2", menuName = "Perception/Labeling Configuration 2", order = 1)]
public class LabelingConfiguration2 : ScriptableObject
{
/// <summary>
/// Whether the inspector will auto-assign ids based on the id of the first element.
/// </summary>
public bool AutoAssignIds = true;
/// <summary>
/// Whether the inspector will start label ids at zero or one when <see cref="AutoAssignIds"/> is enabled.
/// </summary>
public StartingLabelId StartingLabelId = StartingLabelId.One;
[SerializeField]
public List<string> Labels = new List<string>();
/// <summary>
/// A sequence of <see cref="LabelEntry"/> which defines the labels relevant for this configuration and their values.
/// </summary>
[FormerlySerializedAs("LabelingConfigurations")]
[SerializeField]
public List<LabelFeature> LabelFeatures = new List<LabelFeature>();
/// <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>
/// <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++)
{
var entry = LabelEntries[i];
if (string.Equals(entry.label, labelingClass))
{
labelEntry = entry;
labelEntryIndex = i;
return true;
}
}
}
labelEntryIndex = -1;
labelEntry = default;
return false;
}
}
/// <summary>
/// Structure defining a label configuration for <see cref="LabelingConfiguration"/>.
/// </summary>
[Serializable]
public class LabelFeature
{
public string key;
}
[Serializable]
public class StringLabelFeature : LabelFeature
{
public List<string> values;
}
[Serializable]
public class IntLabelFeature : LabelFeature
{
public List<string> values;
}
[Serializable]
public class ColorLabelFeature : LabelFeature
{
public List<string> values;
}
}

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


fileFormatVersion: 2
guid: ef6f93cc88964359a505ccc75835fd5a
timeCreated: 1589581072
正在加载...
取消
保存