浏览代码

UI working for database exporter

/coco_export
Steve Borkman 3 年前
当前提交
6f30a796
共有 8 个文件被更改,包括 88 次插入88 次删除
  1. 34
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  2. 62
      com.unity.perception/Runtime/GroundTruth/Exporters/Coco/CocoExporter.cs
  3. 17
      com.unity.perception/Runtime/GroundTruth/Exporters/PerceptionFormat/PerceptionExporter.cs
  4. 2
      com.unity.perception/Runtime/GroundTruth/Exporters/IDatasetExporter.cs.meta
  5. 8
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  6. 18
      com.unity.perception/Runtime/GroundTruth/Exporters/IDatasetExporter.cs
  7. 35
      com.unity.perception/Runtime/GroundTruth/Exporters/DatasetExporter.cs
  8. 0
      /com.unity.perception/Runtime/GroundTruth/Exporters/IDatasetExporter.cs.meta

34
com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Perception.GroundTruth.Exporters;
using UnityEngine.Perception.GroundTruth.Exporters.PerceptionFormat;
namespace UnityEditor.Perception.GroundTruth
{

Dictionary<SerializedProperty, CameraLabelerDrawer> m_CameraLabelerDrawers = new Dictionary<SerializedProperty, CameraLabelerDrawer>();
ReorderableList m_LabelersList;
string[] m_ExporterList;
OutputMode m_OutputMode = OutputMode.Perception;
string m_OutputMode = "Perception";
int m_OutputModeIndex = -1;
public void OnEnable()
{

m_LabelersList.onAddCallback += OnAdd;
m_LabelersList.onRemoveCallback += OnRemove;
m_OutputMode = (OutputMode)PlayerPrefs.GetInt(SimulationState.outputFormatMode, 0);
m_OutputMode = PlayerPrefs.GetString(SimulationState.outputFormatMode);
m_ExporterList = TypeCache.GetTypesDerivedFrom<IDatasetExporter>().Select(exporter => exporter.Name).ToArray();
if (m_ExporterList.Any())
m_OutputModeIndex = Array.IndexOf(m_ExporterList, m_OutputMode);
m_OutputMode = PlayerPrefs.GetString(SimulationState.outputFormatMode, "Perception");
}
float GetElementHeight(int index)

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.showVisualizations)), new GUIContent("Show Labeler Visualizations", "Display realtime visualizations for labelers that are currently active on this camera."));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.captureRgbImages)),new GUIContent("Save Camera RGB Output to Disk", "For each captured frame, save an RGB image of the camera's output to disk."));
var mode = (OutputMode)EditorGUILayout.EnumPopup("Output Format", m_OutputMode);
if (mode != m_OutputMode)
if (m_ExporterList.Any())
m_OutputMode = mode;
PlayerPrefs.SetInt(SimulationState.outputFormatMode, (int)m_OutputMode);
if (m_OutputModeIndex < 0)
{
m_OutputMode = nameof(PerceptionExporter);
Debug.LogWarning($"Could not find the output format \'{m_OutputMode}\' in the list of available exporters, setting the exporter to \'{m_OutputMode}\'");
m_OutputModeIndex = Array.IndexOf(m_ExporterList, m_OutputMode);
}
var selected = EditorGUILayout.Popup(new GUIContent("Output Format", ""), m_OutputModeIndex, m_ExporterList);
if (m_OutputModeIndex != selected)
{
m_OutputModeIndex = selected;
m_OutputMode = m_ExporterList[selected];
PlayerPrefs.SetString(SimulationState.outputFormatMode, m_OutputMode);
}
}
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.captureTriggerMode)),new GUIContent("Capture Trigger Mode", $"The method of triggering captures for this camera. In {nameof(CaptureTriggerMode.Scheduled)} mode, captures happen automatically based on a start frame and frame delta time. In {nameof(CaptureTriggerMode.Manual)} mode, captures should be triggered manually through calling the {nameof(perceptionCamera.RequestCapture)} method of {nameof(PerceptionCamera)}."));

62
com.unity.perception/Runtime/GroundTruth/Exporters/Coco/CocoExporter.cs


namespace UnityEngine.Perception.GroundTruth.Exporters.Coco
{
public class CocoExporter : DatasetExporter
public class CocoExporter : IDatasetExporter
bool m_PrettyPrint = true;
bool m_ReportingObjectDetection;
bool m_ReportingKeypoints;

Guid m_SessionGuid;
public override string GetName()
{
return "COCO";
}
public override void OnSimulationBegin(string directoryName)
public void OnSimulationBegin(string directoryName)
{
m_DirectoryName = directoryName;
m_DataCaptured = false;

}
public override async void OnSimulationEnd()
public async void OnSimulationEnd()
{
if (!m_DataCaptured) return;

{
await WriteObjectDetectionFile(true);
await WriteObjectDetectionFile();
await WriteKeypointFile(true);
await WriteKeypointFile();
}
File.Delete(m_RgbCaptureFilename);

aggregated.Append(buffer, start, length);
}
async Task WriteObjectDetectionFile(bool prettyPrint = false)
async Task WriteObjectDetectionFile()
{
var stringBuilder = new StringBuilder();

var json = stringBuilder.ToString();
if (prettyPrint)
if (m_PrettyPrint)
{
json = JToken.Parse(json).ToString(Formatting.Indented);
}

File.Delete(m_ObjectDetectionCategoryFilename);
}
async Task WriteKeypointFile(bool prettyPrint = false)
async Task WriteKeypointFile()
{
var stringBuilder = new StringBuilder();

var json = stringBuilder.ToString();
if (prettyPrint)
if (m_PrettyPrint)
{
json = JToken.Parse(json).ToString(Formatting.Indented);
}

}
}
public override void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values)
public void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values)
{
InitializeCaptureFiles();

}
}
public static string versionEntry = "0.0.1";
public static string descriptionEntry = "Description of dataset";
public static string contributorEntry = "Anonymous";
public static string urlEntry = "Not Set";
static string versionEntry = "0.0.1";
static string descriptionEntry = "Description of dataset";
static string contributorEntry = "Anonymous";
static string urlEntry = "Not Set";
public static CocoTypes.License[] licenses = new []
{
new CocoTypes.License
{
id = 0,
name = "No License",
url = "Not Set"
}
};
static void CreateHeaderInfo(StringBuilder stringBuilder)
{

static void CreateLicenseInfo(StringBuilder stringBuilder)
{
var licenses = new CocoTypes.Licenses
{
licenses = new[]
{
new CocoTypes.License
{
id = 0,
name = "No License",
url = "Not Set"
}
}
};
var tmpJson = JsonUtility.ToJson(licenses);
// Remove the start and end '{' from the licenses json

};
}
public override async Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState)
public async Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState)
{
var boxJson = string.Empty;
var keypointJson = string.Empty;

return map;
}
public override async Task OnCaptureReported(int frame, int width, int height, string filename)
public async Task OnCaptureReported(int frame, int width, int height, string filename)
{
InitializeCaptureFiles();

17
com.unity.perception/Runtime/GroundTruth/Exporters/PerceptionFormat/PerceptionExporter.cs


namespace UnityEngine.Perception.GroundTruth.Exporters.PerceptionFormat
{
public class PerceptionExporter : DatasetExporter
public class PerceptionExporter : IDatasetExporter
public override string GetName()
{
return "Perception";
}
public override void OnSimulationBegin(string directoryName)
public void OnSimulationBegin(string directoryName)
public override void OnSimulationEnd()
public void OnSimulationEnd()
public override void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values)
public void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values)
{
// do nothing :-)
}

Manager.Instance.ConsumerFileProduced(path);
}
public override Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState)
public Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState)
{
//lazily allocate for fast zero-write frames
var capturesJArray = new JArray();

return null;
}
public override Task OnCaptureReported(int frame, int width, int height, string filename)
public Task OnCaptureReported(int frame, int width, int height, string filename)
{
// do nothing :-)
return null;

2
com.unity.perception/Runtime/GroundTruth/Exporters/IDatasetExporter.cs.meta


fileFormatVersion: 2
guid: 4059d02ba7a9f37438dd97e5dae05283
guid: 28e95774bd5a26d47973d1213bcc4c26
MonoImporter:
externalObjects: {}
serializedVersion: 2

8
com.unity.perception/Runtime/GroundTruth/SimulationState.cs


HashSet<Guid> m_Ids = new HashSet<Guid>();
Guid m_SequenceId = Guid.NewGuid();
IDatasetReporter m_ActiveReporter = new PerceptionExporter();
IDatasetExporter m_ActiveReporter = new PerceptionExporter();
// Always use the property SequenceTimeMs instead
int m_FrameCountLastUpdatedSequenceTime;

public SimulationState(string outputDirectory)
{
var mode = (OutputMode)PlayerPrefs.GetInt(outputFormatMode, 0);
var mode = PlayerPrefs.GetString(outputFormatMode, nameof(PerceptionExporter));
OutputMode.Perception => new PerceptionExporter(),
OutputMode.COCO => new CocoExporter(),
nameof(PerceptionExporter) => new PerceptionExporter(),
nameof(CocoExporter) => new CocoExporter(),
_ => m_ActiveReporter
};

18
com.unity.perception/Runtime/GroundTruth/Exporters/IDatasetExporter.cs


using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace UnityEngine.Perception.GroundTruth.Exporters
{
public interface IDatasetExporter
{
public void OnSimulationBegin(string directoryName);
public void OnSimulationEnd();
public void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values);
public Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState);
public Task OnCaptureReported(int frame, int width, int height, string filename);
}
}

35
com.unity.perception/Runtime/GroundTruth/Exporters/DatasetExporter.cs


using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace UnityEngine.Perception.GroundTruth.Exporters
{
public abstract class DatasetExporter : MonoBehaviour
{
public void Reset()
{
SimulationState.RegisterExporter(this);
}
public void OnEnable()
{
SimulationState.RegisterExporter(this);
}
public void OnDisable()
{
SimulationState.DeregisterExporter(this);
}
public abstract string GetName();
public abstract void OnSimulationBegin(string directoryName);
public abstract void OnSimulationEnd();
public abstract void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values);
public abstract Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState);
public abstract Task OnCaptureReported(int frame, int width, int height, string filename);
}
}

/com.unity.perception/Runtime/GroundTruth/Exporters/DatasetExporter.cs.meta → /com.unity.perception/Runtime/GroundTruth/Exporters/IDatasetExporter.cs.meta

正在加载...
取消
保存