浏览代码

scheme based labeling almost done. starting asset preparation.

/main
Mohsen Kamalzadeh 4 年前
当前提交
f5483a2f
共有 5 个文件被更改,包括 100 次插入106 次删除
  1. 168
      com.unity.perception/Editor/GroundTruth/LabelingEditor.cs
  2. 8
      com.unity.perception/Editor/AssetPreparation.meta
  3. 19
      com.unity.perception/Editor/AssetPreparation/AssetPreparationTools.cs
  4. 11
      com.unity.perception/Editor/AssetPreparation/AssetPreparationTools.cs.meta

168
com.unity.perception/Editor/GroundTruth/LabelingEditor.cs


});
}
void UpdateActivenessOfUiElements()
bool SerializedObjectHasValidLabelingScheme(SerializedObject serObj)
{
var schemeName = serObj.FindProperty(nameof(Labeling.autoLabelingSchemeType)).stringValue;
return IsValidLabelingSchemeName(schemeName);
}
bool IsValidLabelingSchemeName(string schemeName)
{
return schemeName != string.Empty &&
m_LabelingSchemes.FindAll(scheme => scheme.GetType().Name == schemeName).Count > 0;
}
void UpdateUiAspects()
if (serializedObject.targetObjects.Length > 1)
if (!m_AutoLabelingToggle.value || serializedObject.targetObjects.Length > 1 ||
!SerializedObjectHasValidLabelingScheme(new SerializedObject(serializedObject.targetObjects[0])))
{
m_CurrentAutoLabel.style.display = DisplayStyle.None;
}
else
{
m_CurrentAutoLabel.style.display = DisplayStyle.Flex;
}
if (serializedObject.targetObjects.Length == 1)
{
m_AutoLabelingToggle.text = "Use Automatic Labeling";
}
else
m_CurrentAutoLabel.style.display = DisplayStyle.None;
m_AutoLabelingToggle.text = "Use Automatic Labeling for All Selected Items";
}
}
void UpdateCurrentAutoLabelValue(SerializedObject serObj)
{
var array = serObj.FindProperty(nameof(Labeling.labels));
if (array.arraySize > 0)
{
m_CurrentAutoLabel.text = array.GetArrayElementAtIndex(0).stringValue;
// if (m_LabelingSchemesPopup.index == 0)
// {
// m_CurrentAutoLabel.style.display = DisplayStyle.None;
//
// }
}
void InitializeLabelingSchemes(VisualElement parent)

void AutoLabelToggleChanged()
{
UpdateActivenessOfUiElements();
UpdateUiAspects();
if (serializedObject.targetObjects.Length == 1)
{
SyncAutoLabelWithSchemeSingleTarget(true);
}
// if (serializedObject.targetObjects.Length == 1)
// {
// SyncAutoLabelWithSchemeSingleTarget(true);
// }
}
else
{

serObj.FindProperty(nameof(Labeling.useAutoLabeling)).boolValue = false;
var schemeName = serObj.FindProperty(nameof(Labeling.autoLabelingSchemeType)).stringValue;
if (schemeName != String.Empty)
if (SerializedObjectHasValidLabelingScheme(serObj))
serObj.FindProperty(nameof(Labeling.autoLabelingSchemeType)).stringValue = string.Empty;
m_LabelingSchemesPopup.index = 0;
UpdateActivenessOfUiElements();
if (m_LabelingSchemesPopup.index == 0)
{
return;

string topAssetAutoLabel = String.Empty;
foreach (var targetObj in serializedObject.targetObjects)
{

BackupManualLabels(serObj);
var serLabelsArray = serObj.FindProperty(nameof(Labeling.labels));
serLabelsArray.ClearArray();
serLabelsArray.InsertArrayElementAtIndex(0);

{
topAssetAutoLabel = label;
UpdateCurrentAutoLabelValue(serObj);
m_CurrentAutoLabel.text = topAssetAutoLabel;
}
void AssignAutomaticLabelToSerializedObject(SerializedObject serObj, string labelingSchemeName)
{
var labelingScheme = m_LabelingSchemes.Find(scheme => scheme.GetType().Name == labelingSchemeName);
AssignAutomaticLabelToSerializedObject(serObj, labelingScheme);
UpdateUiAspects();
RefreshManualLabelingData();
}
void AssignAutomaticLabelToSerializedObject(SerializedObject serObj, AssetLabelingScheme labelingScheme)

BackupManualLabels(serObj);
serLabelsArray.ClearArray();
serLabelsArray.InsertArrayElementAtIndex(0);
serLabelsArray.GetArrayElementAtIndex(0).stringValue = label;

void BackupManualLabels(SerializedObject serObj)
{
// var serLabelsArray = serObj.FindProperty(nameof(Labeling.labels));
// var backupLabelsArray = serObj.FindProperty(nameof(Labeling.manualLabelsBackup));
// backupLabelsArray.ClearArray();
// for (int i = 0; i < serLabelsArray.arraySize; i++)
// {
// backupLabelsArray.InsertArrayElementAtIndex(i);
// backupLabelsArray.GetArrayElementAtIndex(i).stringValue =
// serLabelsArray.GetArrayElementAtIndex(i).stringValue;
// }
}
void RetrieveFromManualLabelsBackupArray(SerializedObject serObj)
{
// var serLabelsArray = serObj.FindProperty(nameof(Labeling.labels));
// var backupLabelsArray = serObj.FindProperty(nameof(Labeling.manualLabelsBackup));
// serLabelsArray.ClearArray();
// for (int i = 0; i < backupLabelsArray.arraySize; i++)
// {
// serLabelsArray.InsertArrayElementAtIndex(i);
// serLabelsArray.GetArrayElementAtIndex(i).stringValue =
// backupLabelsArray.GetArrayElementAtIndex(i).stringValue;
// }
}
void SyncAutoLabelWithSchemeSingleTarget(bool enableAutoLabeling = false)
{
var serObj = new SerializedObject(serializedObject.targetObjects[0]);
var currentLabelingSchemeName = serObj.FindProperty(nameof(Labeling.autoLabelingSchemeType)).stringValue;
if (currentLabelingSchemeName != String.Empty)
{
if (enableAutoLabeling)
{
//the useAutoLabeling flag is only turned on for an asset if a valid scheme for auto labeling has also been chosen, that is why it is deferred to here instead of immediately on toggle click
serObj.FindProperty(nameof(Labeling.useAutoLabeling)).boolValue = true;
}
AssignAutomaticLabelToSerializedObject(serObj, currentLabelingSchemeName);
var labelsArray = serObj.FindProperty(nameof(Labeling.labels));
if (labelsArray.arraySize > 0)
{
var autoLabel = labelsArray.GetArrayElementAtIndex(0).stringValue;
m_CurrentAutoLabel.text = autoLabel;
}
m_LabelingSchemesPopup.index =
m_LabelingSchemes.FindIndex(scheme => scheme.GetType().Name.ToString() == currentLabelingSchemeName) + 1;
}
else
{
}
}
m_AutoLabelingToggle.text = "Use Automatic Labeling";
m_CurrentAutoLabel.style.display = DisplayStyle.Flex;
SyncAutoLabelWithSchemeSingleTarget();
var currentLabelingSchemeName = serObj.FindProperty(nameof(Labeling.autoLabelingSchemeType)).stringValue;
if (IsValidLabelingSchemeName(currentLabelingSchemeName))
{
m_LabelingSchemesPopup.index =
m_LabelingSchemes.FindIndex(scheme => scheme.GetType().Name.ToString() == currentLabelingSchemeName) + 1;
}
UpdateCurrentAutoLabelValue(serObj);
m_AutoLabelingToggle.text = "Use Automatic Labeling for All Selected Items";
m_CurrentAutoLabel.style.display = DisplayStyle.None;
foreach (var targetObj in serializedObject.targetObjects)
{

allAssetsUseSameLabelingScheme = false;
}
}
if (targetObj == serializedObject.targetObjects[0])
{
var labelsArray = serObj.FindProperty(nameof(Labeling.labels));
if (labelsArray.arraySize > 0)
{
var autoLabelOfTopSelectedItem = labelsArray.GetArrayElementAtIndex(0).stringValue;
m_CurrentAutoLabel.text = autoLabelOfTopSelectedItem;
}
}
//}
}
m_AutoLabelingToggle.value = enabledOrNot;

}
}
if (!enabledOrNot)
m_CurrentAutoLabel.text = String.Empty;
UpdateUiAspects();
UpdateActivenessOfUiElements();
}
HashSet<string> CreateUnionOfAllLabels()

{
string label2 = commonLabels[j];
if (String.Equals(label, label2) && !commonsIndexToLabelsIndex.ContainsKey(j))
if (string.Equals(label, label2) && !commonsIndexToLabelsIndex.ContainsKey(j))
{
commonsIndexToLabelsIndex.Add(j, i);
}

8
com.unity.perception/Editor/AssetPreparation.meta


fileFormatVersion: 2
guid: 0c2b01a759f934aa099b2949e1580c97
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

19
com.unity.perception/Editor/AssetPreparation/AssetPreparationTools.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Perception.AssetPreparation
{
public class CreatePrefabFromSelectedAssets : MonoBehaviour
{
/// <summary>
/// Function for creating prefabs from multiple models with one click. Created prefabs will be placed in the same folder as their corresponding model.
/// </summary>
[MenuItem("Assets/Perception/Create Prefabs from Selected Models")]
static void CreatePrefabsFromSelectedModels()
{
}
}
}

11
com.unity.perception/Editor/AssetPreparation/AssetPreparationTools.cs.meta


fileFormatVersion: 2
guid: c9787ce9a433e4916b180bf69288f689
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存