浏览代码

Merge remote-tracking branch 'origin/master' into keypoint_self_occlusion

/keypoint_self_occlusion
Jon Hogins 3 年前
当前提交
0ec551af
共有 122 个文件被更改,包括 11521 次插入2170 次删除
  1. 2
      .yamato/environments.yml
  2. 2
      .yamato/upm-ci-performance.yml
  3. 6
      .yamato/upm-ci-testprojects.yml
  4. 21
      README.md
  5. 14
      TestProjects/PerceptionURP/Packages/packages-lock.json
  6. 45
      com.unity.perception/CHANGELOG.md
  7. 35
      com.unity.perception/Documentation~/GroundTruthLabeling.md
  8. 9
      com.unity.perception/Documentation~/HPTutorial/TUTORIAL.md
  9. 7
      com.unity.perception/Documentation~/Randomization/Index.md
  10. 1
      com.unity.perception/Documentation~/Schema/Synthetic_Dataset_Schema.md
  11. 999
      com.unity.perception/Documentation~/Schema/image_0.png
  12. 999
      com.unity.perception/Documentation~/Tutorial/Images/di_usim_2.png
  13. 589
      com.unity.perception/Documentation~/Tutorial/Images/build_uploaded.png
  14. 597
      com.unity.perception/Documentation~/Tutorial/Images/runinusim.png
  15. 13
      com.unity.perception/Documentation~/Tutorial/Phase3.md
  16. 2
      com.unity.perception/Documentation~/Tutorial/TUTORIAL.md
  17. 5
      com.unity.perception/Documentation~/Tutorial/Phase1.md
  18. 34
      com.unity.perception/Documentation~/Tutorial/Phase2.md
  19. 12
      com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor.cs
  20. 70
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  21. 13
      com.unity.perception/Editor/Randomization/Utilities/UIElementsEditorUtilities.cs
  22. 5
      com.unity.perception/Editor/Randomization/Utilities/StaticData.cs
  23. 2
      com.unity.perception/Editor/Randomization/Uxml/Sampler/SamplerInterfaceElement.uxml
  24. 7
      com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml
  25. 16
      com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml
  26. 16
      com.unity.perception/Editor/Randomization/VisualElements/Parameter/ParameterElement.cs
  27. 15
      com.unity.perception/Editor/Randomization/VisualElements/Sampler/SamplerInterfaceElement.cs
  28. 221
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  29. 15
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  30. 2
      com.unity.perception/Runtime/GroundTruth/DatasetJsonUtility.cs
  31. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs
  32. 51
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  33. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
  34. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
  35. 4
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  36. 22
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  37. 10
      com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
  38. 109
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Utilities/GameObjectOneWayCache.cs
  39. 3
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/SerializationStructures.cs
  40. 5
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  41. 18
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  42. 145
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  43. 4
      com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs
  44. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetJsonUtilityTests.cs
  45. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs
  46. 15
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/Resources/SampleScenarioConfiguration.json
  47. 55
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs
  48. 4
      com.unity.perception/package.json
  49. 15
      TestProjects/PerceptionURP/ProjectSettings/BurstAotSettings_StandaloneOSX.json
  50. 994
      com.unity.perception/Documentation~/Randomization/Images/randomization_uml.png
  51. 250
      com.unity.perception/Documentation~/images/labeling_uml.png
  52. 140
      com.unity.perception/Documentation~/images/unity-wide-whiteback.png
  53. 8
      com.unity.perception/Editor/Pyrception.meta
  54. 51
      com.unity.perception/Editor/Randomization/PropertyDrawers/UIntDrawer.cs
  55. 11
      com.unity.perception/Editor/Randomization/PropertyDrawers/UIntDrawer.cs.meta
  56. 11
      com.unity.perception/Editor/Randomization/PropertyDrawers/AssetSourceDrawer.cs.meta
  57. 26
      com.unity.perception/Editor/Randomization/PropertyDrawers/AssetSourceDrawer.cs
  58. 22
      com.unity.perception/Editor/Randomization/Utilities/AssetLoadingUtilities.cs
  59. 11
      com.unity.perception/Editor/Randomization/Utilities/AssetLoadingUtilities.cs.meta
  60. 8
      com.unity.perception/Editor/Randomization/Uxml/AssetSource.meta
  61. 8
      com.unity.perception/Editor/Randomization/VisualElements/Basic.meta
  62. 8
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource.meta
  63. 8
      com.unity.perception/Editor/Visualizer.meta
  64. 8
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources.meta
  65. 8
      com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests.meta
  66. 43
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ExampleDelayRandomizer.cs
  67. 11
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ExampleDelayRandomizer.cs.meta
  68. 1001
      com.unity.perception/Documentation~/FAQ/images/inner_objects.png
  69. 1001
      com.unity.perception/Documentation~/FAQ/images/inner_labels.gif
  70. 229
      com.unity.perception/Documentation~/FAQ/images/cluster_randomizer.png
  71. 199
      com.unity.perception/Documentation~/FAQ/images/prefab_cluster.png
  72. 1001
      com.unity.perception/Documentation~/FAQ/images/hdrp.png
  73. 1001
      com.unity.perception/Documentation~/FAQ/images/hdrp_pt_128_samples.png
  74. 1001
      com.unity.perception/Documentation~/FAQ/images/hdrp_pt_4096_samples.png
  75. 1001
      com.unity.perception/Documentation~/FAQ/images/hdrp_rt_gi.png
  76. 419
      com.unity.perception/Documentation~/FAQ/images/volume.png
  77. 609
      com.unity.perception/Documentation~/FAQ/FAQ.md
  78. 10
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetListElement.uxml
  79. 10
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetListElement.uxml.meta
  80. 7
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetListItemElement.uxml
  81. 10
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetListItemElement.uxml.meta
  82. 10
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetSourceElement.uxml.meta
  83. 26
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetSourceElement.uxml
  84. 11
      com.unity.perception/Editor/Randomization/VisualElements/Basic/UIntField.cs.meta
  85. 11
      com.unity.perception/Editor/Randomization/VisualElements/Basic/UxmlUIntAttributeDescription.cs.meta
  86. 136
      com.unity.perception/Editor/Randomization/VisualElements/Basic/UIntField.cs
  87. 52
      com.unity.perception/Editor/Randomization/VisualElements/Basic/UxmlUIntAttributeDescription.cs
  88. 11
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetListElement.cs.meta
  89. 39
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetListItemElement.cs
  90. 11
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetListItemElement.cs.meta
  91. 11
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetSourceElement.cs.meta

2
.yamato/environments.yml


- name: standalone
display_name: standalone
args: --suite=playmode --platform=
suites:
- name: standalone
display_name: standalone

2
.yamato/upm-ci-performance.yml


agent:
type: Unity::VM::GPU
model: rtx2080
image: cds-ops/ubuntu-18.04-base:latest
image: cds-ops/ubuntu-18.04-base:stable
flavor: b1.large
variables:
PATH: /root/.local/bin:/home/bokken/bin:/home/bokken/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin:/home/bokken/.npm-global/bin

6
.yamato/upm-ci-testprojects.yml


commands:
- git submodule update --init --recursive
- unity-downloader-cli -u {{ editor.version }} -c editor -c StandaloneSupport-IL2CPP -c Linux --wait --published
- .\.Editor\Unity.exe -projectPath ./TestProjects/PerceptionHDRP -testPlatform editmode -runTests -automated -testResults test-results -debugCodeOptimization -enableCodeCoverage -coverageResultsPath test-results --category=!Performance -coverageOptions enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport; assemblyFilters:Unity.Perception.Editor;Unity.Perception.Runtime;Unity.Perception.Sensors;
- .\.Editor\Unity.exe -projectPath ./TestProjects/PerceptionHDRP -testPlatform playmode -runTests -automated -testResults test-results -debugCodeOptimization -enableCodeCoverage -coverageResultsPath test-results --category=!Performance -coverageOptions enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport; assemblyFilters:Unity.Perception.Editor;Unity.Perception.Runtime;Unity.Perception.Sensors;
- .\.Editor\Unity.exe -projectPath ./TestProjects/PerceptionHDRP -testPlatform editmode -runTests -automated -testResults test-results -debugCodeOptimization -enableCodeCoverage -coverageResultsPath test-results --category=!Performance -coverageOptions enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport;assemblyFilters:+Unity.Perception.Runtime
- .\.Editor\Unity.exe -projectPath ./TestProjects/PerceptionHDRP -testPlatform playmode -runTests -automated -testResults test-results -debugCodeOptimization -enableCodeCoverage -coverageResultsPath test-results --category=!Performance -coverageOptions enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport;assemblyFilters:+Unity.Perception.Runtime
# - .\.Editor\Unity.exe -projectPath ./TestProjects/PerceptionHDRP -debugCodeOptimization -enableCodeCoverage -coverageResultsPath test-results -coverageOptions enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport;
artifacts:
logs:

agent:
type: Unity::VM::GPU
model: rtx2080
image: cds-ops/ubuntu-18.04-base:latest
image: cds-ops/ubuntu-18.04-base:stable
flavor: b1.large
variables:
PATH: /root/.local/bin:/home/bokken/bin:/home/bokken/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin:/home/bokken/.npm-global/bin

21
README.md


<img src="com.unity.perception/Documentation~/images/unity-wide.png" align="middle" width="3000"/>
<img src="com.unity.perception/Documentation~/images/unity-wide-whiteback.png" align="middle" width="3000"/>
<img src="com.unity.perception/Documentation~/images/banner2.PNG" align="middle"/>

<img src="https://img.shields.io/badge/unity-2019.4-green.svg?style=flat-square" alt="unity 2019.4">
<img src="https://img.shields.io/badge/unity-2020.2-green.svg?style=flat-square" alt="unity 2020.2">
<img src="https://img.shields.io/badge/unity-2020.2-green.svg?style=flat-square" alt="unity 2020.3">
> com.unity.perception is in active development. Its features and API are subject to significant change as development progresses.
> `com.unity.perception` is in active development. Its features and API are subject to significant change as development progresses.
# Perception Package ([Unity Computer Vision](https://unity.com/computer-vision))

**[Human Pose Labeling and Randomization Tutorial](com.unity.perception/Documentation~/HPTutorial/TUTORIAL.md)**
Step by step instructions for using the keypoint, pose, and animation randomization tools included in the Perception package. It is recommended that you finish Phase 1 of the Perception Tutorial above before starting this tutorial.
**[FAQ](com.unity.perception/Documentation~/FAQ/FAQ.md)**
Check out our FAQ for a list of common questions, tips, tricks, and some sample code.
## Documentation
In-depth documentation on individual components of the package.

|[Dataset Capture](com.unity.perception/Documentation~/DatasetCapture.md)|Ensures sensors are triggered at proper rates and accepts data for the JSON dataset.|
|[Randomization](com.unity.perception/Documentation~/Randomization/Index.md)|The Randomization tool set lets you integrate domain randomization principles into your simulation.|
## Community and Support
For setup problems or discussions about leveraging the Perception package in your project, please create a new thread on the **[Unity Computer Vision forum](https://forum.unity.com/forums/computer-vision.626/)** and make sure to include as much detail as possible. If you run into any other problems with the Perception package or have a specific feature request, please submit a **[GitHub issue](https://github.com/Unity-Technologies/com.unity.perception/issues)**.
For any other questions or feedback, connect directly with the Computer Vision team at [computer-vision@unity3d.com](mailto:computer-vision@unity3d.com).
## Example Projects
### SynthDet

## License
* [License](com.unity.perception/LICENSE.md)
## Community and Feedback
For setup problems or discussions about leveraging the Perception package in your project, please create a new thread on the [Unity Computer Vision forum](https://forum.unity.com/forums/computer-vision.626/) and make sure to include as much detail as possible. If you run into any other problems with the Perception package or have a specific feature request, please submit a [GitHub issue](https://github.com/Unity-Technologies/com.unity.perception/issues).
For any other questions or feedback, connect directly with the Computer Vision team at [computer-vision@unity3d.com](mailto:computer-vision@unity3d.com).
## Citation
If you find this package useful, consider citing it using:

14
TestProjects/PerceptionURP/Packages/packages-lock.json


"com.unity.collections": "0.9.0-preview.6",
"com.unity.nuget.newtonsoft-json": "1.1.2",
"com.unity.render-pipelines.core": "7.1.6",
"com.unity.simulation.capture": "0.0.10-preview.20",
"com.unity.simulation.capture": "0.0.10-preview.23",
"com.unity.simulation.client": "0.0.10-preview.10",
"com.unity.simulation.core": "0.0.10-preview.22"
}

"url": "https://packages.unity.com"
},
"com.unity.simulation.capture": {
"version": "0.0.10-preview.20",
"version": "0.0.10-preview.23",
"com.unity.simulation.core": "0.0.10-preview.22"
"com.unity.simulation.core": "0.0.10-preview.25"
},
"url": "https://packages.unity.com"
},

"url": "https://packages.unity.com"
},
"com.unity.simulation.core": {
"version": "0.0.10-preview.22",
"depth": 1,
"version": "0.0.10-preview.25",
"depth": 2,
"dependencies": {},
"dependencies": {
"com.unity.nuget.newtonsoft-json": "2.0.0-preview"
},
"url": "https://packages.unity.com"
},
"com.unity.sysroot": {

45
com.unity.perception/CHANGELOG.md


### Known Issues
### Added
The user can now choose the base folder location to store their generated datasets.
Added the AssetSource class for loading assets from generic sources inside randomizers.
Users can now choose the base folder location to store their generated datasets.
Added a `projection` field in the capture.sensor metadata. Values are either "perspective" or "orthographic".
Users can now delay the current iteration for one frame from within randomizers by calling the `DelayIteration` function of the active scenario.
### Changed
Changed the JSON serialization key of Normal Sampler's standard deviation property from "standardDeviation" to "stddev". Scneario JSON configurations that were generated using previous versions will need to be manually updated to reflect this change.
### Deprecated
### Removed
### Fixed
Fixed an indexing issue with the IdLabelConfig editor. When a new label was added to an empty Id Label Config with Auto Assign IDs enabled, the starting id (0 or 1) was ignored and the new label would always have an id of 0.
## [0.8.0-preview.4] - 2021-07-05
### Upgrade Notes
### Known Issues
When using URP in OSX, having MSAA enabled on the camera while the post-processing option is disabled may cause the output RGB images to be blank. As a workaround, you can disable MSAA and use FXAA instead, until the issue is fixed.
### Added
Added random seed field to the Run in Unity Simulation Window.
Added support for keypoint self occlusion.
Added the ability to adjust keypoint self occlusion tolerance per keypoint in keypoint template file.

Added a Keypoint Occlusion Override component which allows a user to universally scale all of the keypoint tolerances for a model.
### Changed
Increased color variety in instance segmentation images
Increased color variety in instance segmentation images.
Upgraded capture package dependency to 0.0.10-preview.23 to fix two issues: (1) Post processing effects were not included when capturing images in URP (2) RGB images were upside-down when post processing effects were enabled and FXAA disabled.
### Deprecated

Fixed an issue where Simulation Delta Time values larger than 100 seconds (in Perception Camera) would cause incorrect capture scheduling behavior.
Fixed an issue where Simulation Delta Time values larger than 100 seconds in Perception Camera would cause incorrect capture scheduling behavior.
Fixed an issue where Categorical Parameters sometimes tried to fetch items at `i = categories.Count`, which caused an exception.
## [0.8.0-preview.3] - 2021-03-24
### Changed

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.

9
com.unity.perception/Documentation~/HPTutorial/TUTORIAL.md


* [Step 5: Add Joints to the Character and Customize Keypoint Templates](#step-5)
* [Step 6: Randomize the Humanoid Character's Animations](#step-6)
> :information_source: If you face any problems while following this tutorial, please create a post on the **[Unity Computer Vision forum](https://forum.unity.com/forums/computer-vision.626/)** or the **[GitHub issues](https://github.com/Unity-Technologies/com.unity.perception/issues)** page and include as much detail as possible.
### <a name="step-1">Step 1: Import `.fbx` Models and Animations</a>
This tutorial assumes that you have already created a Unity project, installed the Perception package, and set up a Scene with a `Perception Camera` inside. If this is not the case, please follow **steps 1 to 3** of [Phase 1 of the Perception Tutorial](../Tutorial/Phase1.md).

</p>
* **:green_circle: Action**: Return to `Perception Camera` and assign `HPE_IdLabelConfig` to the `KeyPointLabeler`'s label configuration property.
* **:green_circle: Action**: Search in the _**Project**_ tab for `CocoKeypointTemplate`, with the scope set to _**In Packages**_. Drag and drop the found asset into the `Active Template` field of the `Perception Camera`.
</p>
</p>
Note the `CocoKeypointTemplate` asset that is already assigned as the `Active Template`. This template will tell the labeler how to map default Unity rig joints to human joint labels in the popular COCO dataset so that the output of the labeler can be easily converted to COCO format. Later in this tutorial, we will learn how to add more joints to our character and how to customize joint mapping templates.
The `Active Template` tells the labeler how to map default Unity rig joints to human joint labels in the popular COCO dataset so that the output of the labeler can be easily converted to COCO format. Later in this tutorial, we will learn how to add more joints to our character and how to customize joint mapping templates.
<p align="center">
<img src="Images/take_objects_keypoints.gif" width="600"/>

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

1
com.unity.perception/Documentation~/Schema/Synthetic_Dataset_Schema.md


translation: <float, float, float> -- Position in meters: (x, y, z) with respect to the ego coordinate system. This is typically fixed during the simulation, but we can allow small variation for domain randomization.
rotation: <float, float, float, float> -- Orientation as quaternion: (w, x, y, z) with respect to ego coordinate system. This is typically fixed during the simulation, but we can allow small variation for domain randomization.
camera_intrinsic: <3x3 float matrix> [optional] -- Intrinsic camera calibration. Empty for sensors that are not cameras.
projection: <string> -- holds the type of projection the camera used for that capture: Options: "perspective" or "orthographic"
# add arbitrary optional key-value pairs for sensor attributes
}

999
com.unity.perception/Documentation~/Schema/image_0.png
文件差异内容过多而无法显示
查看文件

999
com.unity.perception/Documentation~/Tutorial/Images/di_usim_2.png
文件差异内容过多而无法显示
查看文件

589
com.unity.perception/Documentation~/Tutorial/Images/build_uploaded.png

之前 之后
宽度: 1382  |  高度: 841  |  大小: 68 KiB

597
com.unity.perception/Documentation~/Tutorial/Images/runinusim.png

之前 之后
宽度: 1212  |  高度: 812  |  大小: 61 KiB

13
com.unity.perception/Documentation~/Tutorial/Phase3.md


Here, you can specify a name for the run, the number of Iterations the Scenario will execute for, and the number of Instances (number of nodes the work will be distributed across) for the run. This window automatically picks the currently active Scene and Scenario to run in Unity Simulation.
* **:green_circle: Action**: Name your run `FirstRun`, set the number of Iterations to `1000`, and Instances to `20`.
* **:green_circle: Action**: Name your run `FirstRun`, set the number of Iterations to `1000`, and Instances to `20`.
* **:green_circle: Action**: If you'd like to use a new random seed for this run of your Scenario, click `Randomize` to generate a new seed.
* **:green_circle: Action**: Click _**Build and Run**_.
> :information_source: You can ignore the ***Optional Configuration*** section for now. This is useful if you plan to specify a configuration for your Scenario (including the Randomizers) that will override the values set in the Scenario UI, in Unity Simulation. To generate a configuration, you can click on the ***Generate JSON Config*** button provided in the ***Inspector*** view of Scenario components.

```
name id creation time
--------------------- ---------------------------------------- ---------------------------
Perception Tutorial acd31956-582b-4138-bec8-6670be150f09 * 2020-09-30T00:33:41+00:00
Perception Tutorial 38baa0d0-a2cd-4ee1-801b-39ca3fc5cbc6 * 2020-09-30T00:33:41+00:00
SynthDet 9ec23417-73cd-becd-9dd6-556183946153 2020-08-12T19:46:20+00:00
```

An example output with 3 runs would look like this:
```
Active Project ID: acd31956-582b-4138-bec8-6670be150f09
Active Project ID: 38baa0d0-a2cd-4ee1-801b-39ca3fc5cbc6
yegz4WN In_Progress 2020-10-01 23:17:54
ojE8Z20 In_Progress 2020-10-01 23:17:54
Run2 klvfxgT 2020-10-01 21:46:39 id status created_at
--------- ------------- ---------------------
kML3i50 In_Progress 2020-10-01 21:46:42

You can also obtain a list of all the builds you have uploaded to Unity Simulation using the `usim get builds` command.
You may notice that the IDs seen above for the run named `FirstRun` match those we saw earlier in Unity Editor's _**Console**_. You can see here that the single execution for our recently uploaded build is `In_Progress` and that the execution ID is `yegz4WN`.
You may notice that the IDs seen above for the run named `FirstRun` match those we saw earlier in Unity Editor's _**Console**_. You can see here that the single execution for our recently uploaded build is `In_Progress` and that the execution ID is `ojE8Z20`.
Unity Simulation utilizes the ability to run simulation Instances in parallel. If you enter a number larger than 1 for the number of Instances in the _**Run in Unity Simulation**_ window, your run will be parallelized, and multiple simulation Instances will simultaneously execute. You can view the status of all simulation Instances using the `usim summarize run-execution <execution-id>` command. This command will tell you how many Instances have succeeded, failed, have not run yet, or are in progress. Make sure to replace `<execution-id>` with the execution ID seen in your run list. In the above example, this ID would be `yegz4WN`.
Unity Simulation utilizes the ability to run simulation Instances in parallel. If you enter a number larger than 1 for the number of Instances in the _**Run in Unity Simulation**_ window, your run will be parallelized, and multiple simulation Instances will simultaneously execute. You can view the status of all simulation Instances using the `usim summarize run-execution <execution-id>` command. This command will tell you how many Instances have succeeded, failed, have not run yet, or are in progress. Make sure to replace `<execution-id>` with the execution ID seen in your run list. In the above example, this ID would be `ojE8Z20`.
* **:green_circle: Action**: Use the `usim summarize run-execution <execution-id>` command to observe the status of your execution nodes:

2
com.unity.perception/Documentation~/Tutorial/TUTORIAL.md


<img src="../images/unity-wide.png" align="middle" width="3000"/>
<img src="../images/unity-wide-whiteback.png" align="middle" width="3000"/>
# Perception Tutorial

5
com.unity.perception/Documentation~/Tutorial/Phase1.md


* [Step 7: Inspect Generated Synthetic Data](#step-7)
* [Step 8: Verify Data Using Dataset Insights](#step-8)
> :information_source: If you face any problems while following this tutorial, please create a post on the **[Unity Computer Vision forum](https://forum.unity.com/forums/computer-vision.626/)** or the **[GitHub issues](https://github.com/Unity-Technologies/com.unity.perception/issues)** page and include as much detail as possible.
### <a name="step-1">Step 1: Download Unity Editor and Create a New Project</a>
* **:green_circle: Action**: Navigate to [this](https://unity3d.com/get-unity/download/archive) page to download and install the latest version of **Unity Editor 2020.2.x**. (The tutorial has not yet been fully tested on newer versions.)

- Semantic segmentation images (if the `SemanticSegmentationLabeler` is added and active on `Perception Camera`)
The output dataset includes a variety of information about different aspects of the active sensors in the Scene (currently only one), as well as the ground-truth generated by all active Labelers. [This page](https://github.com/Unity-Technologies/com.unity.perception/blob/master/com.unity.perception/Documentation%7E/Schema/Synthetic_Dataset_Schema.md) provides a comprehensive explanation on the schema of this dataset. We strongly recommend having a look at the page once you have completed this tutorial.
> :information_source: Are the RGB images blank? This may be a bug. When using URP in OSX, having MSAA enabled on the camera may cause the output RGB images to be blank. As a workaround, you can disable MSAA and use FXAA instead, until the issue is fixed. To do this, select `Main Camera`, and in the ***Inspector*** view of the Camera component, in the ***Output*** section, set MSAA to `Off`. If you would like to use FXAA, in the ***Rendering*** section, set the Anti-aliasing option to `Fast Approximate Anti-aliasing (FXAA)`.
* **:green_circle: Action**: To get a quick feel of how the data is stored, open the folder whose name starts with `Dataset`, then open the file named `captures_000.json`. This file contains the output from `BoundingBox2DLabeler`. The `captures` array contains the position and rotation of the sensor (camera), the position and rotation of the ego (sensor group, currently only one), and the annotations made by `BoundingBox2DLabeler` for all visible objects defined in its label configuration. For each visible object, the annotations include:
* `label_id`: The numerical id assigned to this object's label in the Labeler's label configuration

34
com.unity.perception/Documentation~/Tutorial/Phase2.md


The purpose of this piece of code is to obtain a random float Parameter and assign it to the light's `Intensity` field on the start of every Iteration. Let's go through the code above and understand each part. The `FloatParameter` field makes it possible for us to define a randomized float Parameter and modify its properties from the editor UI, similar to how we already modified the properties for the previous Randomizers we used.
> :information_source: If you look at the _**Console**_ tab of the editor now, you will see an error regarding `MyLightRandomizerTag` not being found. This is to be expected, since we have not yet created this class; the error will go away once we create the class later.
If you return to your list of Randomizers in the _**Inspector**_ view of `SimulationScenario`, you can now add this new Randomizer.
* **:green_circle: Action**: Add `MyLightRandomizer` to the list of Randomizers in `SimulationScenario`.
You will notice that the Randomizer's UI snippet contains one Parameter named `Light Intensity Parameter`. This is the same Parameter we added in the code block above. Here, you can set the sampling distribution (`Value`) and `Range` for this float Parameter:
<p align="center">
<img src="Images/light_rand_1.png" width="420"/>
</p>
* **:green_circle: Action**: In the UI snippet for `MyLightRandomzier`, set the minimum and maximum for range to **0.5** and **3**.
This range of intensities is arbitrary but will give us a typically nice lighting without excessive darkness or burnt-out highlights.
> :information_source: If you look at the _**Console**_ tab of the editor now, you will see an error regarding `MyLightRandomizerTag` not being found. This is normal, because we have not yet created this class; the error will go away once we create the class later.
The `MyLightRandomizer` class extends `Randomizer`, which is the base class for all Randomizers that can be added to a Scenario. This base class provides a plethora of useful functions and properties that can help catalyze the process of creating new Randomizers.

Yes, a RandomizerTag can be this simple if you just need it for helping Randomizers query for target objects. Later, you will learn how to add code here to encapsulate more data and logic within the randomized objects.
Notice there is a `RequireComponent(typeof(Light))` line at the top. This line makes it so that you can only add the `MyLightRandomizerTag` component to an object that already has a `Light` component attached. This way, the Randomizers that query for this tag can be confident that the found tags are attached to GameObjects that also have a `Light` component, and can thus be Randomized.
If you return to your list of Randomizers in the _**Inspector**_ view of `SimulationScenario`, you can now add the new Randomizer we created here.
* **:green_circle: Action**: Add `MyLightRandomizer` to the list of Randomizers in `SimulationScenario`.
You will notice that the Randomizer's UI snippet contains one Parameter named `Light Intensity Parameter`. This is the same Parameter we added in the code block above. Here, you can set the sampling distribution (`Value`) and `Range` for this float Parameter:
<p align="center">
<img src="Images/light_rand_1.png" width="420"/>
</p>
* **:green_circle: Action**: In the UI snippet for `MyLightRandomzier`, set the minimum and maximum for range to **0.5** and **3**.
This range of intensities is arbitrary but will give us a typically nice lighting without excessive darkness or burnt-out highlights.
It is now time to add the tag we created earlier to the light in our Scene, so that the Randomizer can find it.
* **:green_circle: Action**: Select `Directional Light` in the Scene's _**Hierarchy**_, and in the _**Inspector**_ tab, add a `My Light Randomizer Tag` component.
* **:green_circle: Action**: Run the simulation again and inspect how `Directional Light` now switches between different intensities. You can pause the simulation and then use the step button (to the right of the pause button) to move the simulation one frame forward and clearly see the varying light intensity

12
com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor.cs


protected override IdLabelEntry CreateLabelEntryFromLabelString(SerializedProperty serializedArray,
string labelToAdd)
{
int maxLabel = Int32.MinValue;
var maxLabel = int.MinValue;
for (int i = 0; i < serializedArray.arraySize; i++)
for (var i = 0; i < serializedArray.arraySize; i++)
}
if (maxLabel == -1)
{
var startingLabelId =
(StartingLabelId) serializedObject.FindProperty(nameof(IdLabelConfig.startingLabelId)).enumValueIndex;
if (startingLabelId == StartingLabelId.One)
maxLabel = 0;
}
return new IdLabelEntry

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


using System;
using System;
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
using UnityEditor.Perception.Visualizer;
#endif
namespace UnityEditor.Perception.GroundTruth
{

m_LabelersList.DoLayoutList();
}
var s = new GUIStyle(EditorStyles.textField);
s.wordWrap = true;
var defaultColor = s.normal.textColor;
EditorGUILayout.LabelField("Latest Output Folder");
EditorGUILayout.LabelField("Latest Generated Dataset");
EditorGUILayout.HelpBox(dir, MessageType.None);
s.normal.textColor = Color.green;
EditorGUILayout.LabelField(dir, s);
if (GUILayout.Button("Show Folder"))
{
EditorUtility.RevealInFinder(dir);

GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
GUILayout.Space(10);
var userBaseDir = PlayerPrefs.GetString(SimulationState.userBaseDirectoryKey);
if (userBaseDir == string.Empty)
{
var folder = PlayerPrefs.GetString(SimulationState.defaultOutputBaseDirectory);
userBaseDir = folder != string.Empty ? folder : Application.persistentDataPath;
}
EditorGUILayout.LabelField("Output Base Folder");
GUILayout.BeginVertical("TextArea");
s.normal.textColor = defaultColor;
EditorGUILayout.LabelField(userBaseDir, s);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Change Folder"))
{
var path = EditorUtility.OpenFolderPanel("Choose Output Folder", "", "");
if (path.Length != 0)
{
Debug.Log($"Chose path: {path}");
PlayerPrefs.SetString(SimulationState.userBaseDirectoryKey, path);
}
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
GUILayout.Space(10);
EditorGUILayout.LabelField("Visualizer Tool");
GUILayout.BeginHorizontal("TextArea");
if (GUILayout.Button("Open Visualizer"))
{
var project = Application.dataPath;
_=VisualizerInstaller.RunVisualizer(project);
}
if (GUILayout.Button("Check For Updates"))
{
var project = Application.dataPath;
_=VisualizerInstaller.CheckForUpdates();
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
#endif
if (EditorSettings.asyncShaderCompilation)
{

13
com.unity.perception/Editor/Randomization/Utilities/UIElementsEditorUtilities.cs


{
var propertyField = new PropertyField(iterator.Copy());
propertyField.Bind(iterator.serializedObject);
var originalField = parentPropertyType.GetField(iterator.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
FieldInfo originalField;
do
{
originalField = parentPropertyType.GetField(iterator.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
parentPropertyType = parentPropertyType.BaseType;
}
while (originalField == null && parentPropertyType != null) ;
if (originalField == null)
return null;
var tooltipAttribute = originalField.GetCustomAttributes(true)
.ToList().Find(att => att.GetType() == typeof(TooltipAttribute));
if (tooltipAttribute != null)

5
com.unity.perception/Editor/Randomization/Utilities/StaticData.cs


using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.Perception.Randomization;
using UnityEngine.Perception.Randomization.Randomizers;
using UnityEngine.Perception.Randomization.Samplers;

internal static Type[] randomizerTypes;
internal static Type[] samplerTypes;
internal static Type[] assetSourceLocationTypes;
internal static Type[] assetRoleTypes;
assetSourceLocationTypes = GetConstructableDerivedTypes<AssetSourceLocation>();
assetRoleTypes = GetConstructableDerivedTypes<IAssetRoleBase>();
}
static Type[] GetConstructableDerivedTypes<T>()

2
com.unity.perception/Editor/Randomization/Uxml/Sampler/SamplerInterfaceElement.uxml


<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
<VisualElement name="sampler-template" style="margin-bottom: 4px;">
<VisualElement style="margin-bottom: 4px;">
<Style src="../../Uss/Styles.uss"/>
<VisualElement style="flex-direction: row; align-items: center;">
<Label name="sampler-name" text="Sampler Name" class="unity-base-field__label"/>

7
com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml


class="scenario__info-box"
text="Scenarios control the execution flow of your simulation by applying randomization parameters. Make sure to always have only one scenario active within your scene."/>
<VisualElement name="constants-container">
<editor:PropertyField
name="configuration-asset"
label="Configuration"
binding-path="configuration"
style="margin-left: 13 px;"
tooltip="References a JSON configuration text asset to load at runtime before the scenario starts executing. Scenario configuration files can be created using the Generate JSON Config button below."/>
<editor:PropertyField name="configuration-file-name" label="Constants File Name" binding-path="serializedConstantsFileName"/>
<VisualElement style="flex-direction: row;">
<Button name="generate-json-config" text="Generate JSON Config" style="flex-grow: 1;"
tooltip="Serializes scenario constants and randomizer settings to a JSON configuration file"/>

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


tooltip="The number of scenario iterations to execute"/>
<editor:IntegerField name="instance-count" label="Instance Count" max-value="10000"
tooltip="The number of instances to distribute the work load across"/>
<VisualElement style="flex-direction: row;">
<editor:UIntField name="random-seed" label="Random Seed" style="flex-grow: 1;"
tooltip="The initial random seed to use for the simulation"/>
<Button name="randomize-seed" text="Randomize"/>
</VisualElement>
<VisualElement class="unity-base-field"
tooltip="The compute resources configuration to execute the simulation with">
<Label text="Sys-Param" class="unity-base-field__label"/>

tooltip="Selects a scenario JSON configuration to load during the run.
You can leave this option blank to use the scenario settings currently configured in the editor."/>
<editor:EnumField name="build-type-menu" label="Build type" style="flex-grow:1; margin:0; border-width: 1px;"/>
<VisualElement name="build-select-controls" style="margin-bottom: 0; flex-direction: row; justify-content: space-between; align-items: center;">
<TextField name="selected-build-path" label="Build Zip Path" style="flex-grow: 1; flex-shrink: 1;" />
<Button name="select-build-file-button" text="Browse..." style="margin: 0; align-items: flex-end; margin-top: 0; width: 70px;" />
</VisualElement>
<TextField name="build-id" label="Build ID" style="flex-grow: 1; flex-shrink: 1;" />
<VisualElement style="align-items: center; margin-top: 8px;">
<Button name="run-button" text="Build and Run" style="margin: 10px; padding: 2 20; font-size: 13px;"/>
</VisualElement>

<Label name="prev-run-name" text="Run Name: " class="sim-window__label-prev-result"/>
<Label name="project-id" text="Project ID: " class="sim-window__label-prev-result"/>
<Label name="execution-id" text="Execution ID: " class="sim-window__label-prev-result"/>
<Label name="prev-random-seed" text="Random Seed: " class="sim-window__label-prev-result"/>
<Button name="copy-prev-random-seed" text="Copy Seed" style="flex-grow: 1; flex-shrink: 0;"/>
</VisualElement>
</VisualElement>
</VisualElement>

16
com.unity.perception/Editor/Randomization/VisualElements/Parameter/ParameterElement.cs


var listView = template.Q<ListView>("options");
listView.itemsSource = probabilities;
listView.itemHeight = 22;
listView.itemHeight = 44;
listView.selectionType = SelectionType.None;
listView.style.flexGrow = 1.0f;
listView.style.height = new StyleLength(listView.itemHeight * 4);

"Add Options From Folder", Application.dataPath, string.Empty);
if (folderPath == string.Empty)
return;
var categories = LoadAssetsFromFolder(folderPath, categoricalParameter.sampleType);
var categories = AssetLoadingUtilities.LoadAssetsFromFolder(folderPath, categoricalParameter.sampleType);
var optionsIndex = optionsProperty.arraySize;
optionsProperty.arraySize += categories.Count;

});
m_PropertiesContainer.Add(template);
}
static List<Object> LoadAssetsFromFolder(string folderPath, Type assetType)
{
if (!folderPath.StartsWith(Application.dataPath))
throw new ApplicationException("Selected folder is not an asset folder in this project");
var assetsPath = "Assets" + folderPath.Remove(0, Application.dataPath.Length);
var assetIds = AssetDatabase.FindAssets($"t:{assetType.Name}", new[] { assetsPath });
var assets = new List<Object>();
foreach (var guid in assetIds)
assets.Add(AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), assetType));
return assets;
}
}
}

15
com.unity.perception/Editor/Randomization/VisualElements/Sampler/SamplerInterfaceElement.cs


SerializedProperty m_RangeProperty;
ToolbarMenu m_SamplerTypeDropdown;
ISampler sampler => (ISampler)StaticData.GetManagedReferenceValue(m_Property);
public SamplerInterfaceElement(SerializedProperty property)
{
m_Property = property;

CreateSampler(typeof(UniformSampler));
var samplerName = this.Q<Label>("sampler-name");
samplerName.text = UppercaseFirstLetter(m_Property.name);
samplerName.text = m_Property.displayName;
;
foreach (var samplerType in StaticData.samplerTypes)
{
var displayName = SamplerUtility.GetSamplerDisplayName(samplerType);

a => { ReplaceSampler(samplerType); },
a => ReplaceSampler(samplerType),
ISampler sampler => (ISampler)StaticData.GetManagedReferenceValue(m_Property);
void ReplaceSampler(Type samplerType)
{

m_RangeProperty = null;
m_PropertiesContainer.Clear();
UIElementsEditorUtilities.CreatePropertyFields(m_Property, m_PropertiesContainer);
}
static string UppercaseFirstLetter(string s)
{
return string.IsNullOrEmpty(s) ? string.Empty : char.ToUpper(s[0]) + s.Substring(1);
}
}
}

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


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Perception.Randomization.Samplers;
using Random = System.Random;
private const string m_SupportedGPUString = "Tesla";
string m_BuildDirectory;
string m_BuildZipPath;
SysParamDefinition[] m_SysParamDefinitions;

UIntField m_RandomSeedField;
ToolbarMenu m_SysParamMenu;
int m_SysParamIndex;
ObjectField m_ScenarioConfigField;

Label m_PrevExecutionIdLabel;
Label m_PrevRandomSeedLabel;
const string k_SupportedGPUString = "NVIDIA";
const string m_SupportedGPUString = "NVIDIA";
EnumField m_BuildTypeMenu;
VisualElement m_BuildSelectControls;
TextField m_BuildPathField;
TextField m_SelectedBuildPathTextField;
TextField m_BuildIdField;
[MenuItem("Window/Run in Unity Simulation")]
static void ShowWindow()

}
}
enum BuildIdKind
{
BuildPlayer,
ExistingBuildID,
ExistingBuildZip
}
void CreateRunInUnitySimulationUI()
{
var root = rootVisualElement;

m_RunNameField = root.Q<TextField>("run-name");
m_TotalIterationsField = root.Q<IntegerField>("total-iterations");
m_InstanceCountField = root.Q<IntegerField>("instance-count");
m_RandomSeedField = root.Q<UIntField>("random-seed");
var randomizeSeedButton = root.Q<Button>("randomize-seed");
randomizeSeedButton.clicked += () =>
{
var bytes = new byte[4];
new Random().NextBytes(bytes);
m_RandomSeedField.value = BitConverter.ToUInt32(bytes, 0);
};
m_SysParamDefinitions = API.GetSysParams();
m_SysParamMenu = root.Q<ToolbarMenu>("sys-param");

m_PrevRunNameLabel = root.Q<Label>("prev-run-name");
m_ProjectIdLabel = root.Q<Label>("project-id");
m_PrevExecutionIdLabel = root.Q<Label>("execution-id");
m_PrevRandomSeedLabel = root.Q<Label>("prev-random-seed");
var copyExecutionIdButton = root.Q<Button>("copy-execution-id");
copyExecutionIdButton.clicked += () =>

copyProjectIdButton.clicked += () =>
EditorGUIUtility.systemCopyBuffer = CloudProjectSettings.projectId;
var copyPrevRandomSeedButton = root.Q<Button>("copy-prev-random-seed");
copyPrevRandomSeedButton.clicked += () =>
EditorGUIUtility.systemCopyBuffer = PlayerPrefs.GetString("SimWindow/prevRandomSeed");
m_BuildTypeMenu = root.Q<EnumField>("build-type-menu");
m_BuildTypeMenu.Init(BuildIdKind.BuildPlayer);
m_BuildTypeMenu.RegisterValueChangedCallback(evt => { UpdateBuildIdElements((BuildIdKind) evt.newValue); });
m_BuildSelectControls = root.Q<VisualElement>("build-select-controls");
m_SelectedBuildPathTextField = root.Q<TextField>("selected-build-path");
m_SelectedBuildPathTextField.isReadOnly = true;
m_BuildPathField = root.Q<TextField>("selected-build-path");
m_BuildIdField = root.Q<TextField>("build-id");
UpdateBuildIdElements((BuildIdKind) m_BuildTypeMenu.value);
var selectBuildButton = root.Q<Button>("select-build-file-button");
selectBuildButton.clicked += () =>
{
var path = EditorUtility.OpenFilePanel("Select build ZIP file", "", "zip");
if (path.Length != 0)
{
m_SelectedBuildPathTextField.value = path;
}
};
private void UpdateBuildIdElements(BuildIdKind buildIdKind)
{
switch (buildIdKind)
{
case BuildIdKind.ExistingBuildID:
m_BuildSelectControls.SetEnabled(false);
m_BuildIdField.SetEnabled(true);
break;
case BuildIdKind.ExistingBuildZip:
m_BuildSelectControls.SetEnabled(true);
m_BuildIdField.SetEnabled(false);
break;
case BuildIdKind.BuildPlayer:
m_BuildSelectControls.SetEnabled(false);
m_BuildIdField.SetEnabled(false);
break;
}
}
void SetFieldsFromPlayerPreferences()
{
m_RunNameField.value = IncrementRunName(PlayerPrefs.GetString("SimWindow/runName"));

var prevRandomSeed = PlayerPrefs.GetString("SimWindow/prevRandomSeed");
m_RandomSeedField.value = string.IsNullOrEmpty(prevRandomSeed)
? SamplerUtility.largePrime : uint.Parse(prevRandomSeed);
m_PrevRandomSeedLabel.text = $"Random Seed: {PlayerPrefs.GetString("SimWindow/prevRandomSeed")}";
}
static string IncrementRunName(string runName)

async void RunInUnitySimulation()
{
#if PLATFORM_CLOUD_RENDERING
if (!m_SysParamDefinitions[m_SysParamIndex].description.Contains(m_SupportedGPUString))
if (!m_SysParamDefinitions[m_SysParamIndex].description.Contains(k_SupportedGPUString))
{
EditorUtility.DisplayDialog("Unsupported Sysparam",
"The current selection of the Sysparam " + m_SysParamDefinitions[m_SysParamIndex].description +

runName = m_RunNameField.value,
totalIterations = m_TotalIterationsField.value,
instanceCount = m_InstanceCountField.value,
randomSeed = m_RandomSeedField.value,
sysParamIndex = m_SysParamIndex,
scenarioConfig = (TextAsset)m_ScenarioConfigField.value,
currentOpenScenePath = SceneManager.GetSceneAt(0).path,

null);
try
{
m_RunButton.SetEnabled(false);
// Upload build
var cancellationTokenSource = new CancellationTokenSource();
var token = cancellationTokenSource.Token;
CreateLinuxBuildAndZip();
await StartUnitySimulationRun(runGuid);
string buildId = null;
var buildIdKind = (BuildIdKind)m_BuildTypeMenu.value;
switch (buildIdKind)
{
case BuildIdKind.BuildPlayer:
if (CreateLinuxBuildAndZip())
{
buildId = await UploadBuild(cancellationTokenSource, token);
}
break;
case BuildIdKind.ExistingBuildZip:
m_BuildZipPath = m_BuildPathField.value;
buildId = await UploadBuild(cancellationTokenSource, token);
break;
case BuildIdKind.ExistingBuildID:
buildId = m_BuildIdField.value;
break;
}
if (buildId == null)
return;
StartUnitySimulationRun(runGuid, buildId);
EditorUtility.ClearProgressBar();
finally
{
m_RunButton.SetEnabled(true);
EditorUtility.ClearProgressBar();
}
}
private async Task<string> UploadBuild(CancellationTokenSource cancellationTokenSource, CancellationToken token)
{
var buildId = await API.UploadBuildAsync(
m_RunParameters.runName,
m_BuildZipPath,
null, null,
cancellationTokenSource,
progress =>
{
EditorUtility.DisplayProgressBar(
"Unity Simulation Run", "Uploading build...", progress * 0.90f);
});
if (token.IsCancellationRequested)
{
Debug.Log("The build upload process has been cancelled. Aborting Unity Simulation launch.");
EditorUtility.ClearProgressBar();
return null;
}
return buildId;
}
void ValidateSettings()

throw new NotSupportedException("Invalid instance count specified");
if (m_RunParameters.totalIterations <= 0)
throw new NotSupportedException("Invalid total iteration count specified");
if (string.IsNullOrEmpty(m_RunParameters.currentOpenScenePath))
throw new MissingFieldException("Invalid scene path");
if (m_RunParameters.currentScenario == null)
throw new MissingFieldException(
"There is not a Unity Simulation compatible scenario present in the scene");

Path.GetExtension(m_RunParameters.scenarioConfigAssetPath) != ".json")
throw new NotSupportedException(
"Scenario configuration must be a JSON text asset");
if (((BuildIdKind)m_BuildTypeMenu.value) == BuildIdKind.ExistingBuildZip &&
!File.Exists(m_SelectedBuildPathTextField.value))
{
throw new NotSupportedException(
"Selected build path does not exist");
}
if (((BuildIdKind)m_BuildTypeMenu.value) == BuildIdKind.ExistingBuildID &&
String.IsNullOrEmpty(m_BuildIdField.value))
{
throw new NotSupportedException("Empty Build ID");
}
void CreateLinuxBuildAndZip()
bool CreateLinuxBuildAndZip()
List<string> scenes = new List<string>();
foreach(var scene in EditorBuildSettings.scenes)
{
if(scene.enabled)
scenes.Add(scene.path);
}
if (scenes.Count == 0)
{
if (EditorUtility.DisplayDialog("No Scenes Found", "Could not find any enabled Scenes in build settings. Open File -> Build Settings and add all your required Scenes.", "Use Currently Open Scene", "Cancel Build"))
{
var currentOpenScenePath = SceneManager.GetSceneAt(0).path;
if (string.IsNullOrEmpty(currentOpenScenePath))
{
EditorUtility.DisplayDialog("Build Failed", "Could not find an active Scene.", "OK");
throw new Exception($"Could not find an active Scene.");
}
scenes.Add(currentOpenScenePath);
}
else
{
return false;
}
}
scenes = new[] { m_RunParameters.currentOpenScenePath },
scenes = scenes.ToArray(),
locationPathName = Path.Combine(projectBuildDirectory, $"{m_RunParameters.runName}.x86_64"),
#if PLATFORM_CLOUD_RENDERING
target = BuildTarget.CloudRendering,

EditorUtility.DisplayProgressBar("Unity Simulation Run", "Zipping Linux build...", 0f);
Zip.DirectoryContents(projectBuildDirectory, m_RunParameters.runName);
m_BuildZipPath = projectBuildDirectory + ".zip";
return true;
}
List<AppParam> UploadAppParam()

var constants = configuration["constants"];
constants["totalIterations"] = m_RunParameters.totalIterations;
constants["instanceCount"] = m_RunParameters.instanceCount;
constants["randomSeed"] = m_RunParameters.randomSeed;
var appParamName = $"{m_RunParameters.runName}";
var appParamsString = JsonConvert.SerializeObject(configuration, Formatting.Indented);

return appParamIds;
}
async Task StartUnitySimulationRun(Guid runGuid)
void StartUnitySimulationRun(Guid runGuid, string buildId)
m_RunButton.SetEnabled(false);
// Upload build
var cancellationTokenSource = new CancellationTokenSource();
var token = cancellationTokenSource.Token;
var buildId = await API.UploadBuildAsync(
m_RunParameters.runName,
m_BuildZipPath,
null, null,
cancellationTokenSource,
progress =>
{
EditorUtility.DisplayProgressBar(
"Unity Simulation Run", "Uploading build...", progress * 0.90f);
});
if (token.IsCancellationRequested)
{
Debug.Log("The build upload process has been cancelled. Aborting Unity Simulation launch.");
EditorUtility.ClearProgressBar();
return;
}
// Generate and upload app-params
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading app-params...", 0.90f);
var appParams = UploadAppParam();

run.Execute();
// Cleanup
m_RunButton.SetEnabled(true);
EditorUtility.ClearProgressBar();
PerceptionEditorAnalytics.ReportRunInUnitySimulationSucceeded(runGuid, run.executionId);
// Set new Player Preferences

PlayerPrefs.SetInt("SimWindow/instanceCount", m_RunParameters.instanceCount);
PlayerPrefs.SetString("SimWindow/prevRandomSeed", m_RunParameters.randomSeed.ToString());
PlayerPrefs.SetInt("SimWindow/sysParamIndex", m_RunParameters.sysParamIndex);
PlayerPrefs.SetString("SimWindow/scenarioConfig",
m_RunParameters.scenarioConfig != null ? m_RunParameters.scenarioConfigAssetPath : string.Empty);

public string runName;
public int totalIterations;
public int instanceCount;
public uint randomSeed;
public int sysParamIndex;
public TextAsset scenarioConfig;
public string currentOpenScenePath;

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


using System.IO;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Perception.Randomization.Scenarios;
using UnityEngine.UIElements;

m_SerializedObject = new SerializedObject(m_Scenario);
m_Root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/ScenarioBaseElement.uxml").CloneTree();
#if !ENABLE_SCENARIO_APP_PARAM_CONFIG
var configuration = m_Root.Q<PropertyField>("configuration-asset");
configuration.style.display = DisplayStyle.None;
m_Scenario.configuration = null;
EditorUtility.SetDirty(m_Scenario);
#endif
m_RandomizerListPlaceholder = m_Root.Q<VisualElement>("randomizer-list-placeholder");

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.DeserializeConfigurationInternal();
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);

case "constants":
m_HasConstantsField = true;
UIElementsEditorUtilities.CreatePropertyFields(iterator.Copy(), m_ConstantsListVisualContainer);
break;
case "configuration":
break;
default:
{

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


case double v:
return new JValue(v);
case string v:
return new JValue($"\"{v}\"");
return new JValue(v);
case uint v:
return new JValue(v);
}

2
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs


protected override void Setup()
{
if (idLabelConfig == null)
throw new InvalidOperationException("BoundingBox2DLabeler's idLabelConfig field must be assigned");
throw new InvalidOperationException("BoundingBox3DLabeler's idLabelConfig field must be assigned");
m_AnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition("bounding box 3D", idLabelConfig.GetAnnotationSpecification(),
"Bounding box for each labeled object visible to the sensor", id: new Guid(annotationId));

51
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>
internal void Init(PerceptionCamera camera)
{
try
{
perceptionCamera = camera;
sensorHandle = camera.SensorHandle;
Setup();
isInitialized = true;
}
catch (Exception)
{
enabled = false;
throw;
}
}
internal void InternalSetup() => Setup();
internal bool InternalVisualizationEnabled

internal void InternalCleanup() => Cleanup();
internal void InternalVisualize() => OnVisualize();
private bool m_ShowVisualizations = false;
bool m_ShowVisualizationsForLabeler;
/// <summary>
/// Turns on/off the labeler's realtime visualization capability. If a labeler does not support realtime

{
get
{
return supportsVisualization && m_ShowVisualizations;
if (!supportsVisualization)
return false;
return perceptionCamera && perceptionCamera.showVisualizations && m_ShowVisualizationsForLabeler;
if (value != m_ShowVisualizations)
if (value != m_ShowVisualizationsForLabeler)
m_ShowVisualizations = value;
m_ShowVisualizationsForLabeler = value;
OnVisualizerEnabledChanged(m_ShowVisualizations);
OnVisualizerEnabledChanged(m_ShowVisualizationsForLabeler);
}
}
}

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;
}
}
}
}

2
com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs


return json;
}
}
}
}

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


/// <summary>
/// The <see cref="IdLabelConfig"/> which associates objects with labels.
/// </summary>
public IdLabelConfig labelConfig => m_LabelConfig;
public IdLabelConfig labelConfig
{
get => m_LabelConfig;
set => m_LabelConfig = value;
}
/// <summary>
/// Fired when the object counts are computed for a frame.

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


// Record the camera's projection matrix
SetPersistentSensorData("camera_intrinsic", ToProjectionMatrix3x3(cam.projectionMatrix));
// Record the camera's projection type (orthographic or perspective)
SetPersistentSensorData("projection", cam.orthographic ? "orthographic" : "perspective");
var captureFilename = $"{Manager.Instance.GetDirectoryFor(rgbDirectory)}/{k_RgbFilePrefix}{Time.frameCount}.png";
var dxRootPath = $"{rgbDirectory}/{k_RgbFilePrefix}{Time.frameCount}.png";
SensorHandle.ReportCapture(dxRootPath, SensorSpatialData.FromGameObjects(

#else
CaptureCamera.Capture(cam, colorFunctor, flipY: flipY);
#endif
Profiler.EndSample();
}

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


float m_LastTimeScale;
readonly string m_OutputDirectoryName;
string m_OutputDirectoryPath;
public const string userBaseDirectoryKey = "userBaseDirectory";
public const string defaultOutputBaseDirectory = "defaultOutputBaseDirectory";
public bool IsRunning { get; private set; }

public SimulationState(string outputDirectory)
{
PlayerPrefs.SetString(defaultOutputBaseDirectory, Configuration.Instance.GetStorageBasePath());
PlayerPrefs.SetString(latestOutputDirectoryKey, Manager.Instance.GetDirectoryFor());
var basePath = PlayerPrefs.GetString(userBaseDirectoryKey, string.Empty);
if (basePath != string.Empty)
{
if (Directory.Exists(basePath))
{
Configuration.localPersistentDataPath = basePath;
}
else
{
Debug.LogWarning($"Passed in directory to store simulation artifacts: {basePath}, does not exist. Using default directory {Configuration.localPersistentDataPath} instead.");
basePath = Configuration.localPersistentDataPath;
}
}
PlayerPrefs.SetString(latestOutputDirectoryKey, Manager.Instance.GetDirectoryFor("", basePath));
IsRunning = true;
}

m_Ids.Add(egoHandle.Id);
}
public bool IsEnabled(SensorHandle sensorHandle) => m_ActiveSensors.Contains(sensorHandle);
public void SetEnabled(SensorHandle sensorHandle, bool value)

Debug.LogError($"Simulation ended with pending metrics: {string.Join(", ", m_PendingMetrics.Select(c => $"id:{c.MetricId} step:{c.Step}"))}");
WriteReferences();
Time.captureDeltaTime = 0;
IsRunning = false;
}

10
com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs


public T Sample()
{
var randomValue = m_Sampler.Sample();
return uniform
? m_Categories[(int)(randomValue * m_Categories.Count)]
: m_Categories[BinarySearch(randomValue)];
if (uniform)
{
var index = (int)(randomValue * m_Categories.Count);
index = index == m_Categories.Count ? index - 1 : index;
return m_Categories[index];
}
return m_Categories[BinarySearch(randomValue)];
}
/// <summary>

109
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Utilities/GameObjectOneWayCache.cs


using System.Collections.Generic;
using Unity.Profiling;
using UnityEngine;
using UnityEngine.Perception.Randomization.Samplers;
namespace UnityEngine.Perception.Randomization.Randomizers.Utilities
{

{