浏览代码

fixed usim references

/main
Steven Leal 4 年前
当前提交
159fd9dc
共有 13 个文件被更改,包括 79 次插入79 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 28
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  3. 2
      com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml
  4. 2
      com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs
  5. 2
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  6. 4
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
  7. 59
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  8. 59
      com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs
  9. 0
      /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs.meta
  10. 0
      /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  11. 0
      /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml.meta
  12. 0
      /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml
  13. 0
      /com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs.meta

2
com.unity.perception/CHANGELOG.md


### Fixed
USimScenario now correctly deserializes app-params before offsetting the current scenario iteration when executing on Unity Simulation
UnitySimulationScenario now correctly deserializes app-params before offsetting the current scenario iteration when executing on Unity Simulation
Fixed Unity Simulation nodes generating one extra empty image before generating their share of the randomization scenario iterations

28
com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs


using Unity.Simulation.Client;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.SceneManagement;
using UnityEditor.UIElements;
using UnityEngine.Experimental.Perception.Randomization.Editor;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;

namespace UnityEngine.Perception.Randomization.Editor
{
class RunInUSimWindow : EditorWindow
class RunInUnitySimulationWindow : EditorWindow
{
string m_BuildDirectory;

[MenuItem("Window/Run in Unity Simulation")]
static void ShowWindow()
{
var window = GetWindow<RunInUSimWindow>();
var window = GetWindow<RunInUnitySimulationWindow>();
window.titleContent = new GUIContent("Run In Unity Simulation");
window.minSize = new Vector2(250, 50);
window.Show();

}
else
{
CreateRunInUSimUI();
CreateRunInUnitySimulationUI();
}
}

/// <param name="element">The visual element to enable view data for</param>
static void SetViewDataKey(VisualElement element)
{
element.viewDataKey = $"RunInUSim_{element.name}";
element.viewDataKey = $"RunInUnitySimulation_{element.name}";
void CreateRunInUSimUI()
void CreateRunInUnitySimulationUI()
$"{StaticData.uxmlDir}/RunInUSimWindow.uxml").CloneTree(root);
$"{StaticData.uxmlDir}/RunInUnitySimulationWindow.uxml").CloneTree(root);
m_RunNameField = root.Q<TextField>("run-name");
SetViewDataKey(m_RunNameField);

m_SysParam = sysParamDefinitions[0];
m_RunButton = root.Q<Button>("run-button");
m_RunButton.clicked += RunInUSim;
m_RunButton.clicked += RunInUnitySimulation;
async void RunInUSim()
async void RunInUnitySimulation()
await StartUSimRun();
await StartUnitySimulationRun();
}
void ValidateSettings()

if (m_ScenarioField.value == null)
throw new MissingFieldException("Scenario unselected");
var scenario = (ScenarioBase)m_ScenarioField.value;
if (!StaticData.IsSubclassOfRawGeneric(typeof(USimScenario<>), scenario.GetType()))
throw new NotSupportedException("Scenario class must be derived from USimScenario to run in USim");
if (!StaticData.IsSubclassOfRawGeneric(typeof(UnitySimulationScenario<>), scenario.GetType()))
throw new NotSupportedException(
"Scenario class must be derived from UnitySimulationScenario to run in Unity Simulation");
}
void CreateLinuxBuildAndZip()

if (token.IsCancellationRequested)
return null;
var appParamName = $"{m_RunNameField.value}_{i}";
var appParamId = API.UploadAppParam(appParamName, new USimConstants
var appParamId = API.UploadAppParam(appParamName, new UnitySimulationConstants
{
totalIterations = m_TotalIterationsField.value,
instanceCount = m_InstanceCountField.value,

return appParamIds;
}
async Task StartUSimRun()
async Task StartUnitySimulationRun()
{
m_RunButton.SetEnabled(false);
var cancellationTokenSource = new CancellationTokenSource();

2
com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml


<editor:ObjectField name="main-scene" label="Main Scene" allow-scene-objects="false"/>
<editor:ObjectField name="scenario" label="Scenario"/>
<VisualElement class="unity-base-field">
<Label text="USim worker config" class="unity-base-field__label"/>
<Label text="System Parameters" class="unity-base-field__label"/>
<editor:ToolbarMenu name="sys-param" class="unity-base-field__input" style="border-width: 1px;"/>
</VisualElement>
<VisualElement style="align-items: center;">

2
com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs


static SimulationState CreateSimulationData()
{
//TODO: Remove the Guid path when we have proper dataset merging in USim/Thea
//TODO: Remove the Guid path when we have proper dataset merging in Unity Simulation and Thea
return new SimulationState($"Dataset{k_DatasetGuid}");
}

2
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


[RequireComponent(typeof(Camera))]
public partial class PerceptionCamera : MonoBehaviour
{
//TODO: Remove the Guid path when we have proper dataset merging in USim/Thea
//TODO: Remove the Guid path when we have proper dataset merging in Unity Simulation and Thea
internal static string RgbDirectory { get; } = $"RGB{Guid.NewGuid()}";
static string s_RgbFilePrefix = "rgb_";

4
com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs


/// A scenario that runs for a fixed number of frames during each iteration
/// </summary>
[AddComponentMenu("Perception/Randomization/Scenarios/Fixed Length Scenario")]
public class FixedLengthScenario: USimScenario<FixedLengthScenario.Constants>
public class FixedLengthScenario: UnitySimulationScenario<FixedLengthScenario.Constants>
public class Constants : USimConstants
public class Constants : UnitySimulationConstants
{
/// <summary>
/// The number of frames to generate per iteration

59
com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs


using System;
using Unity.Simulation;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{
/// <summary>
/// Defines a scenario that is compatible with the Run in Unity Simulation window
/// </summary>
/// <typeparam name="T">The type of constants to serialize</typeparam>
public abstract class UnitySimulationScenario<T> : Scenario<T> where T : UnitySimulationConstants, new()
{
/// <summary>
/// Returns whether the entire scenario has completed
/// </summary>
public sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <summary>
/// Progresses the current scenario iteration
/// </summary>
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;
}
/// <summary>
/// Deserializes this scenario's constants from the Unity Simulation AppParams Json file
/// </summary>
public sealed override void Deserialize()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
constants = Configuration.Instance.GetAppParams<T>();
else
base.Deserialize();
currentIteration = constants.instanceIndex;
}
}
/// <summary>
/// A class encapsulating the scenario constants fields required for Unity Simulation cloud execution
/// </summary>
[Serializable]
public class UnitySimulationConstants
{
/// <summary>
/// The total number of iterations to run a scenario for
/// </summary>
public int totalIterations = 100;
/// <summary>
/// The number of Unity Simulation instances assigned to executed this scenario
/// </summary>
public int instanceCount = 1;
/// <summary>
/// The Unity Simulation instance index of the currently executing worker
/// </summary>
public int instanceIndex;
}
}

59
com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs


using System;
using Unity.Simulation;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{
/// <summary>
/// Defines a scenario that is compatible with the Run in USim window
/// </summary>
/// <typeparam name="T">The type of constants to serialize</typeparam>
public abstract class USimScenario<T> : Scenario<T> where T : USimConstants, new()
{
/// <summary>
/// Returns whether the entire scenario has completed
/// </summary>
public sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <summary>
/// Progresses the current scenario iteration
/// </summary>
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;
}
/// <summary>
/// Deserializes this scenario's constants from the USim AppParams Json file
/// </summary>
public sealed override void Deserialize()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
constants = Configuration.Instance.GetAppParams<T>();
else
base.Deserialize();
currentIteration = constants.instanceIndex;
}
}
/// <summary>
/// A class encapsulating the scenario constants fields required for USim cloud execution
/// </summary>
[Serializable]
public class USimConstants
{
/// <summary>
/// The total number of iterations to run a scenario for
/// </summary>
public int totalIterations = 100;
/// <summary>
/// The number of USim instances assigned to executed this scenario
/// </summary>
public int instanceCount = 1;
/// <summary>
/// The USim instance index of the currently executing worker
/// </summary>
public int instanceIndex;
}
}

/com.unity.perception/Editor/Randomization/Editors/RunInUSimWindow.cs.meta → /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs.meta

/com.unity.perception/Editor/Randomization/Editors/RunInUSimWindow.cs → /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs

/com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml.meta → /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml.meta

/com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml → /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml

/com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs.meta → /com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs.meta

正在加载...
取消
保存