浏览代码

Merge branch 'configuration-text-asset' into generic-asset-sources

/generic-asset-sources
sleal-unity 4 年前
当前提交
4c50a0a5
共有 10 个文件被更改,包括 1348 次插入85 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 35
      com.unity.perception/Documentation~/GroundTruthLabeling.md
  3. 7
      com.unity.perception/Documentation~/Randomization/Index.md
  4. 5
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  5. 39
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  6. 80
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  7. 17
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  8. 4
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs
  9. 994
      com.unity.perception/Documentation~/Randomization/Images/randomization_uml.png
  10. 250
      com.unity.perception/Documentation~/images/labeling_uml.png

2
com.unity.perception/CHANGELOG.md


The PoissonDiskSampling utility now samples a larger region of points to then crop to size of the intended region to prevent edge case bias.
Upgraded capture package dependency to 0.0.10-preview.21
Upgraded capture package dependency to 0.0.10-preview.22 to fix an issue with URP where post processing effects were not included when capturing images.
### Deprecated

35
com.unity.perception/Documentation~/GroundTruthLabeling.md


# Labeling
Many labelers require mapping the objects in the view to the values recorded in the dataset. As an example, Semantic Segmentation needs to determine the color to draw each object in the segmentation image.
# Ground Truth Generation
The Perception package includes a set of Labelers which capture ground truth information along with each captured frame. The built-in Labelers support a variety of common computer vision tasks, including 2D and 3D bounding boxes, instance and semantic segmentation, and keypoint labeling (labeled points on 3D objects). The package also includes extensible components for building new Labelers to support additional tasks. Labelers derive ground truth data from labels specified on the GameObjects present in the Scene.
<p align="center">
<img src="images/labeling_uml.png" width="800"/>
<br><i>Class diagram for the ground truth generation system of the Perception package</i>
</p>
## Camera Labeler
A set of Camera Labelers are added to the Perception Camera, each tasked with generating a specific type of ground truth. For instance, the Semantic Segmentation Labeler outputs segmentation images in which each labeled object is rendered in a unique user-definable color and non-labeled objects and the background are rendered black.
## Label Config
The Label Config acts as a mapping between string labels and object classes (currently colors or integers), deciding which labels in the Scene (and thus which objects) should be tracked by the Labeler, and what color (or integer id) they should have in the captured frames.
## Labeling Component
The Labeling component associates a list of string-based labels with a GameObject and its descendants. A Labeling component on a descendant overrides its parent's labels.
## Label Resolution
The Labeling component added to the GameObjects in the Scene works in conjunction with each active Labeler's Label Config, in order to map each labeled GameObject to an object class in the output.
## Labeling component
The Labeling component associates a list of string-based labels with a GameObject and its descendants. A Labeling component on a descendant overrides its parent's labels.
### Limitations
## Limitations
## Label Config
Many labelers require a Label Config asset. This asset specifies a list of all labels to be captured in the dataset along with extra information used by the various labelers.
For example, you could label an asset representing a box of Rice Krispies as `food\cereal\kellogs\ricekrispies`
For example, you can assign four different labels to an asset representing a box of Rice Krispies so as to define an inherent hierarchy:
* "food": type
* "cereal": subtype

If the goal of the algorithm is to identify all objects in a Scene that are "food", that label is available and can be used. Conversely if the goal is to identify only Rice Krispies cereal within a Scene that label is also available. Depending on the goal of the algorithm, you can use any mix of labels in the hierarchy.
This way, you can have Label Configs that include labels from different levels of this hierarchy so that you can easily switch an object's label in the output by switching to a different Label Config. If the goal of the algorithm is to identify all objects in a Scene that are "food", that label is available and can be used if the Label Config only contains "food" and not the other labels of the object. Conversely if the goal is to identify only Rice Krispies cereal within a Scene, that label is also available. Depending on the goal of the algorithm, you can use any mix of labels in the hierarchy.

7
com.unity.perception/Documentation~/Randomization/Index.md


4. Parameters
5. Samplers
<br>
<p align="center">
<img src="Images/randomization_uml.png" width="900"/>
<br><i>Class diagram for the randomization framework included in the Perception package</i>
</p>
## Scenarios

5
com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs


if (string.IsNullOrEmpty(filePath))
return;
Undo.RecordObject(m_Scenario, "Deserialized scenario configuration");
m_Scenario.DeserializeFromFile(filePath);
var originalConfig = m_Scenario.configuration;
m_Scenario.LoadConfigurationFromFile(filePath);
m_Scenario.DeserializeConfiguration();
m_Scenario.configuration = originalConfig;
Debug.Log($"Deserialized scenario configuration from {Path.GetFullPath(filePath)}. " +
"Using undo in the editor will revert these changes to your scenario.");
PlayerPrefs.SetString(k_ConfigFilePlayerPrefKey, filePath);

39
com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs


/// </summary>
protected virtual void Cleanup() {}
/// <summary>
/// Initializes labeler with the target perception camera
/// </summary>
/// <param name="camera">The target perception camera</param>
public void Init(PerceptionCamera camera)
{
try
{
perceptionCamera = camera;
sensorHandle = camera.SensorHandle;
Setup();
isInitialized = true;
m_ShowVisualizations = supportsVisualization && perceptionCamera.showVisualizations;
}
catch (Exception)
{
enabled = false;
throw;
}
}
internal void InternalSetup() => Setup();
internal bool InternalVisualizationEnabled

internal void Visualize()
{
if (visualizationEnabled) OnVisualize();
}
internal void Init(PerceptionCamera newPerceptionCamera)
{
try
{
this.perceptionCamera = newPerceptionCamera;
sensorHandle = newPerceptionCamera.SensorHandle;
Setup();
isInitialized = true;
m_ShowVisualizations = supportsVisualization && perceptionCamera.showVisualizations;
}
catch (Exception)
{
this.enabled = false;
throw;
}
}
}
}

80
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


/// <summary>
/// The list of randomizers managed by this scenario
/// </summary>
[SerializeReference] List<Randomizer> m_Randomizers = new List<Randomizer>();
[HideInInspector, SerializeReference] List<Randomizer> m_Randomizers = new List<Randomizer>();
/// <summary>
/// An external text asset that is loaded when the scenario starts to configure scenario settings
/// </summary>
[HideInInspector] public TextAsset configuration;
/// <summary>
/// Enumerates over all enabled randomizers

ScenarioSerializer.SerializeToFile(this, filePath);
}
/// <summary>
/// Overwrites this scenario's randomizer settings and scenario constants from a JSON serialized configuration
/// </summary>
/// <param name="json">The JSON string to deserialize</param>
public virtual void DeserializeFromJson(string json)
public void LoadConfigurationFromFile(string filePath)
ScenarioSerializer.Deserialize(this, json);
}
/// <summary>
/// Overwrites this scenario's randomizer settings and scenario constants using a configuration file located at
/// the provided file path
/// </summary>
/// <param name="configFilePath">The file path to the configuration file to deserialize</param>
public virtual void DeserializeFromFile(string configFilePath)
{
if (string.IsNullOrEmpty(configFilePath))
throw new ArgumentException($"{nameof(configFilePath)} is null or empty");
if (!File.Exists(configFilePath))
throw new ArgumentException($"No configuration file found at {configFilePath}");
var jsonText = File.ReadAllText(configFilePath);
DeserializeFromJson(jsonText);
#if !UNITY_EDITOR
Debug.Log($"Deserialized scenario configuration from {Path.GetFullPath(configFilePath)}");
#endif
if (!File.Exists(filePath))
throw new FileNotFoundException($"No configuration file found at {filePath}");
var jsonText = File.ReadAllText(filePath);
configuration = new TextAsset(jsonText);
}
/// <summary>

protected virtual void DeserializeFromCommandLine(string commandLineArg="--scenario-config-file")
protected void LoadConfigurationFromCommandLine(string commandLineArg="--scenario-config-file")
{
var args = Environment.GetCommandLineArgs();
var filePath = string.Empty;

return;
}
try { DeserializeFromFile(filePath); }
catch (Exception exception)
{
Debug.LogException(exception);
Debug.LogError("An exception was caught while attempting to parse a " +
$"scenario configuration file at {filePath}. Cleaning up and exiting simulation.");
}
LoadConfigurationFromFile(filePath);
}
/// <summary>
/// Loads and stores a JSON scenario settings configuration file before the scenario starts
/// </summary>
protected virtual void LoadConfigurationAsset()
{
LoadConfigurationFromCommandLine();
}
/// <summary>
/// Overwrites this scenario's randomizer settings and scenario constants from a JSON serialized configuration
/// </summary>
public virtual void DeserializeConfiguration()
{
if (configuration != null)
ScenarioSerializer.Deserialize(this, configuration.text);
}
/// <summary>

/// OnAwake is called when this scenario MonoBehaviour is created or instantiated
/// </summary>
protected virtual void OnAwake() { }
/// <summary>
/// OnConfigurationImport is called before OnStart in the same frame. This method by default loads a scenario
/// settings from a file before the scenario begins.
/// </summary>
protected virtual void OnConfigurationImport()
{
#if !UNITY_EDITOR
DeserializeFromCommandLine();
#endif
}
/// <summary>
/// OnStart is called when the scenario first begins playing

case State.Initializing:
if (isScenarioReadyToStart)
{
OnConfigurationImport();
#if !UNITY_EDITOR
LoadConfigurationAsset();
#endif
DeserializeConfiguration();
state = State.Playing;
OnStart();
foreach (var randomizer in m_Randomizers)

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


/// <inheritdoc/>
protected sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <inheritdoc/>
protected override void OnConfigurationImport()
protected override void LoadConfigurationAsset()
DeserializeFromFile(new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath);
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
var filePath = new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath;
LoadConfigurationFromFile(filePath);
base.OnConfigurationImport();
base.LoadConfigurationAsset();
}
/// <inheritdoc/>
public override void DeserializeConfiguration()
{
base.DeserializeConfiguration();
if (Configuration.Instance.IsSimulationRunningInCloud())
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
currentIteration = constants.instanceIndex;
}

4
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs


// Serialize some values
m_Scenario.constants = constants;
var serializedConfig = m_Scenario.SerializeToJson();
m_Scenario.configuration = new TextAsset(m_Scenario.SerializeToJson());
m_Scenario.DeserializeFromJson(serializedConfig);
m_Scenario.DeserializeConfiguration();
// Check if the values reverted correctly
Assert.AreEqual(m_Scenario.constants.framesPerIteration, constants.framesPerIteration);

994
com.unity.perception/Documentation~/Randomization/Images/randomization_uml.png

之前 之后
宽度: 3124  |  高度: 1304  |  大小: 254 KiB

250
com.unity.perception/Documentation~/images/labeling_uml.png
文件差异内容过多而无法显示
查看文件

正在加载...
取消
保存