浏览代码

Removal of expired visualization artifacts fixes for SynthDet

Removed bounding boxes and HUD entries for objects no longer being visualized, added performance improvements to handle complete scene changes every frame
/aisv647_visualizations
Steven Borkman 4 年前
当前提交
20e13b92
共有 4 个文件被更改,包括 72 次插入43 次删除
  1. 49
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
  2. 26
      com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
  3. 28
      com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
  4. 12
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/HUDPanel.cs

49
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs


AnnotationDefinition m_BoundingBoxAnnotationDefinition;
BoundingBoxValue[] m_BoundingBoxValues;
private Dictionary<string, RectTransform> visualizationPanelCache = null;
private GameObject visualizationHolder = null;
/// <summary>

visualizationEnabled = enabled;
});
visualizationHolder = new GameObject("BoundsHolder");
canvas.AddComponent(visualizationHolder);
objectPool = new List<GameObject>();
visualizationPanelCache = new Dictionary<string, RectTransform>();
visualizationHolder = new GameObject("BoundsHolder" + Time.frameCount);
canvas.AddComponent(visualizationHolder);
void Visualize()
void ClearObjectPool(int count)
foreach (var box in m_BoundingBoxValues)
for (int i = count; i < objectPool.Count; i++)
var rectTrans = GetVisualizationPanel(box.label_name + "_" + box.instance_id);
rectTrans.anchoredPosition = new Vector2(box.x, -box.y);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, box.width);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, box.height);
objectPool[i].SetActive(false);
RectTransform GetVisualizationPanel(string label)
List<GameObject> objectPool = null;
void Visualize()
if (!visualizationPanelCache.ContainsKey(label))
ClearObjectPool(m_BoundingBoxValues.Length);
for (int i = 0; i < m_BoundingBoxValues.Length; i++)
var box = GameObject.Instantiate(Resources.Load<GameObject>("BoundingBoxPrefab"));
box.name = label + "_boundingbox";
box.GetComponentInChildren<Text>().text = label;
box.transform.SetParent(visualizationHolder.transform, false);
visualizationPanelCache[label] = box.transform as RectTransform;
}
var boxVal = m_BoundingBoxValues[i];
return visualizationPanelCache[label];
if (i >= objectPool.Count)
{
objectPool.Add(GameObject.Instantiate(Resources.Load<GameObject>("BoundingBoxPrefab")));
(objectPool[i].transform as RectTransform).parent = visualizationHolder.transform;
}
if (!objectPool[i].activeSelf) objectPool[i].SetActive(true);
string label = boxVal.label_name + "_" + boxVal.instance_id;
objectPool[i].GetComponentInChildren<Text>().text = label;
var rectTrans = objectPool[i].transform as RectTransform;
rectTrans.anchoredPosition = new Vector2(boxVal.x, -boxVal.y);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, boxVal.width);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, boxVal.height);
}
}
/// <inheritdoc/>

26
com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs


Dictionary<int, AsyncMetric> m_ObjectCountAsyncMetrics;
MetricDefinition m_ObjectCountMetricDefinition;
Dictionary<string, string> entryToLabelMap = null;
List<string> vizEntries = null;
/// <summary>
/// Creates a new ObjectCountLabeler. This constructor should only be used by serialization. For creation from

if (m_ClassCountValues == null || m_ClassCountValues.Length != entries.Count)
m_ClassCountValues = new ClassCountValue[entries.Count];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
if (visualize)
{
if (vizEntries == null) vizEntries = new List<string>();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
}
for (var i = 0; i < entries.Count; i++)
{
m_ClassCountValues[i] = new ClassCountValue()

count = counts[i]
};
if (visualizationEnabled && perceptionCamera.visualizationEnabled)
if (visualize)
if (entryToLabelMap == null) entryToLabelMap = new Dictionary<string, string>();
var label = entries[i].label + " Counts";
if (!entryToLabelMap.ContainsKey(entries[i].label)) entryToLabelMap[entries[i].label] = entries[i].label + " Counts";
hudPanel.UpdateEntry(entryToLabelMap[entries[i].label], counts[i].ToString());
hudPanel.UpdateEntry(label, counts[i].ToString());
vizEntries.Add(label);
}
}

{
if (!enabled)
{
foreach (var e in entryToLabelMap)
{
hudPanel.RemoveEntry(e.Value);
}
entryToLabelMap.Clear();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
}
}
}

28
com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs


Dictionary<int, AsyncMetric> m_ObjectInfoAsyncMetrics;
MetricDefinition m_RenderedObjectInfoMetricDefinition;
Dictionary<string, string> entryToLabelMap = null;
List<string> vizEntries = null;
/// <summary>
/// Creates a new RenderedObjectInfoLabeler. Be sure to assign <see cref="idLabelConfig"/> before adding to a <see cref="PerceptionCamera"/>.

if (m_VisiblePixelsValues == null || m_VisiblePixelsValues.Length != renderedObjectInfos.Length)
m_VisiblePixelsValues = new RenderedObjectInfoValue[renderedObjectInfos.Length];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
if (visualize)
{
if (vizEntries == null) vizEntries = new List<string>();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
}
for (var i = 0; i < renderedObjectInfos.Length; i++)
{
var objectInfo = renderedObjectInfos[i];

visible_pixels = objectInfo.pixelCount
};
if (visualizationEnabled && perceptionCamera.visualizationEnabled)
if (visualize)
if (entryToLabelMap == null) entryToLabelMap = new Dictionary<string, string>();
if (!entryToLabelMap.ContainsKey(label)) entryToLabelMap[label] = label + " Pixels";
hudPanel.UpdateEntry(entryToLabelMap[label], objectInfo.pixelCount.ToString());
hudPanel.UpdateEntry(label, objectInfo.pixelCount.ToString());
vizEntries.Add(label);
}
}

bool TryGetLabelEntryFromInstanceId(uint instanceId, out IdLabelEntry labelEntry)
{

{
if (!enabled)
{
foreach (var e in entryToLabelMap)
{
hudPanel.RemoveEntry(e.Value);
}
entryToLabelMap.Clear();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
}
}
}

12
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/HUDPanel.cs


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

img.enabled = entries.Any();
}
// TODO object pooling
/// <summary>
/// Updates (or creates) an entry with the passed in key value pair
/// </summary>

pair.transform.SetParent(null);
Destroy(pair.gameObject);
}
}
/// <summary>
/// Removes all of the list of keys from the HUD
/// </summary>
public void RemoveEntries(List<string> keys)
{
foreach (var k in keys) RemoveEntry(k);
}
}
}
正在加载...
取消
保存