Skip to content

Commit

Permalink
RC 0.11.1-preview.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vvernygora-unity3d committed Apr 14, 2022
1 parent 0a6113c commit 4deadb5
Show file tree
Hide file tree
Showing 37 changed files with 2,091 additions and 201 deletions.
24 changes: 24 additions & 0 deletions com.unity.perception/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

## [0.11.1-preview.1] - 2022-04-13

### Added

Added the ability to define the output of a standalone player with an '--output-path' command line argument

### Changed

Exceptions thrown in randomizers will now end the run

Duplicates in categorical parameters are checked and reported

User output paths are now written out in user's settings

### Fixed

Fixed captured RGB images being upside down or dark in various cases

Fixed UI when there are many randomizers in the project

Fixed Scenario UI when the last randomizer is removed

Fixed the Visualizer installation bug, Visualizer can be installed and opened properly now.

## [0.10.0-preview.1] - 2022-03-09

### Upgrade Notes
Expand Down
110 changes: 75 additions & 35 deletions com.unity.perception/Documentation~/DatasetCapture.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,90 @@ You can register custom sensors using `DatasetCapture.RegisterSensor()`. The `si
`Time.captureDeltaTime` is set at every frame in order to precisely fall on the next sensor that requires simulation, and this includes multi-sensor simulations. For instance, if one sensor has a `simulationDeltaTime` of 2 and another 3, the first five values for `Time.captureDeltaTime` will be 2, 1, 1, 2, and 3, meaning simulation will happen on the timestamps 0, 2, 3, 4, 6, and 9.

## Custom annotations and metrics
In addition to the common annotations and metrics produced by [PerceptionCamera](PerceptionCamera.md), scripts can produce their own via `DatasetCapture`. You must first register annotation and metric definitions using `DatasetCapture.RegisterAnnotationDefinition()` or `DatasetCapture.RegisterMetricDefinition()`. These return `AnnotationDefinition` and `MetricDefinition` instances which you can then use to report values during runtime.
In addition to the common annotations and metrics produced by [PerceptionCamera](PerceptionCamera.md), scripts can produce their own via `DatasetCapture`. You must first create and register annotation and metric definitions using `DatasetCapture.RegisterAnnotationDefinition()` or `DatasetCapture.RegisterMetric()`. These are used~~~~ to report values during runtime.

Annotations and metrics are always associated with the frame they are reported in. They may also be associated with a specific sensor by using the `Report*` methods on `SensorHandle`.

### Example
<!-- If you change this, change it in PerceptionURP/Assets/Examples/CustomAnnotationAndMetricReporter.cs as well -->
```csharp
using System;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.GroundTruth.DataModel;
using UnityEngine.Rendering;

[RequireComponent(typeof(PerceptionCamera))]
public class CustomAnnotationAndMetricReporter : MonoBehaviour
public class CustomLabeler : CameraLabeler
{
public override string description => "Demo labeler";
public override string labelerId => "Demo labeler";
protected override bool supportsVisualization => false;

public GameObject targetLight;
public GameObject target;

MetricDefinition lightMetricDefinition;
AnnotationDefinition boundingBoxAnnotationDefinition;
SensorHandle cameraSensorHandle;
AnnotationDefinition targetPositionDef;

public void Start()
class TargetPositionDef : AnnotationDefinition
{
//Metrics and annotations are registered up-front
lightMetricDefinition = DatasetCapture.RegisterMetricDefinition(
"Light position",
"The world-space position of the light",
Guid.Parse("1F6BFF46-F884-4CC5-A878-DB987278FE35"));
boundingBoxAnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition(
"Target bounding box",
"The position of the target in the camera's local space",
id: Guid.Parse("C0B4A22C-0420-4D9F-BAFC-954B8F7B35A7"));
public TargetPositionDef(string id)
: base(id) { }

public override string modelType => "targetPosDef";
public override string description => "The position of the target in the camera's local space";
}

public void Update()
[Serializable]
class TargetPosition : Annotation
{
public TargetPosition(AnnotationDefinition definition, string sensorId, Vector3 pos)
: base(definition, sensorId)
{
position = pos;
}

public Vector3 position;

public override void ToMessage(IMessageBuilder builder)
{
base.ToMessage(builder);
builder.AddFloatArray("position", MessageBuilderUtils.ToFloatVector(position));
}

public override bool IsValid() => true;

}

protected override void Setup()
{
lightMetricDefinition =
new MetricDefinition(
"LightMetric",
"lightMetric1",
"The world-space position of the light");
DatasetCapture.RegisterMetric(lightMetricDefinition);

targetPositionDef = new TargetPositionDef("target1");
DatasetCapture.RegisterAnnotationDefinition(targetPositionDef);
}

protected override void OnBeginRendering(ScriptableRenderContext scriptableRenderContext)
{
//Report the light's position by manually creating the json array string.
var lightPos = targetLight.transform.position;
DatasetCapture.ReportMetric(lightMetricDefinition,
$@"[{{ ""x"": {lightPos.x}, ""y"": {lightPos.y}, ""z"": {lightPos.z} }}]");
var metric = new GenericMetric(new[] { lightPos.x, lightPos.y, lightPos.z }, lightMetricDefinition);
DatasetCapture.ReportMetric(lightMetricDefinition, metric);

//compute the location of the object in the camera's local space
Vector3 targetPos = transform.worldToLocalMatrix * target.transform.position;
Vector3 targetPos = perceptionCamera.transform.worldToLocalMatrix * target.transform.position;

//Report using the PerceptionCamera's SensorHandle if scheduled this frame
var sensorHandle = GetComponent<PerceptionCamera>().SensorHandle;
var sensorHandle = perceptionCamera.SensorHandle;

if (sensorHandle.ShouldCaptureThisFrame)
{
sensorHandle.ReportAnnotationValues(
boundingBoxAnnotationDefinition,
new[] { targetPos });
var annotation = new TargetPosition(targetPositionDef, sensorHandle.Id, targetPos);
sensorHandle.ReportAnnotation(targetPositionDef, annotation);
}
}
}
Expand All @@ -73,21 +108,26 @@ public class CustomAnnotationAndMetricReporter : MonoBehaviour
// "annotation_id": null,
// "sequence_id": "9768671e-acea-4c9e-a670-0f2dba5afe12",
// "step": 1,
// "metric_definition": "1f6bff46-f884-4cc5-a878-db987278fe35",
// "values": [{ "x": 96.1856, "y": 192.676, "z": -193.8386 }]
// "metric_definition": "lightMetric1",
// "values": [
// 96.1856,
// 192.675964,
// -193.838638
// ]
// },
// Example annotation that is added to each capture in the dataset:
// {
// "id": "33f5a3aa-3e5e-48f1-8339-6cbd64ed4562",
// "annotation_definition": "c0b4a22c-0420-4d9f-bafc-954b8f7b35a7",
// "values": [
// [
// -1.03097284,
// 0.07265166,
// -6.318692
// "annotation_id": "target1",
// "model_type": "targetPosDef",
// "description": "The position of the target in the camera's local space",
// "sensor_id": "camera",
// "id": "target1",
// "position": [
// 1.85350215,
// -0.253945172,
// -5.015307
// ]
// ]
// }
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<TextElement name="directory-label-text" text="Randomizers" style="-unity-font-style: bold; padding: 3px;"/>
<VisualElement/>
</VisualElement>
<VisualElement name="menu-options"/>
<ScrollView name="menu-options"/>
<VisualElement class="randomizer__menu-search-icon"/>
</VisualElement>
</UXML>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ void RefreshList()
return;
}

if (m_Property.arraySize == 0)
{
var textElement = new TextElement()
{
text = "No randomizers added. Add any to resume"
};
textElement.AddToClassList("scenario__error-box");
m_Container.Add(textElement);
}

for (var i = 0; i < m_Property.arraySize; i++)
m_Container.Add(new RandomizerElement(m_Property.GetArrayElementAtIndex(i), this));
}
Expand Down
58 changes: 38 additions & 20 deletions com.unity.perception/Editor/Visualizer/VisualizerInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,48 @@ const string k_NameOfVisualizerProcess
#elif UNITY_EDITOR_WIN
= "datasetvisualizer";
#endif

internal static Task InstallationCommand(ref int exitCode, string packagesPath)

internal static Task InstallationCommand(ref int exitCode, string packagesPath, bool forcePublic)
{
var exitCodeCopy = exitCode;
var pythonPath = Path.Combine(Directory.GetParent(packagesPath)?.ToString() ?? string.Empty, "python.exe");

var indexURL = forcePublic ? string.Empty : GetIndexURL();

#if UNITY_EDITOR_WIN
var task = Task.Run(() => ExecuteCmd($"{pythonPath} -m pip install --upgrade --no-warn-script-location unity-cv-datasetvisualizer {indexURL}", ref exitCodeCopy));
#elif UNITY_EDITOR_OSX
var task = Task.Run(() => ExecuteCmd($"cd {packagesPath}; ./python3.7 -m pip install --upgrade unity-cv-datasetvisualizer {indexURL}", ref exitCodeCopy));
#endif
exitCode = exitCodeCopy;
return task;
}

internal static Task UninstallCommand(ref int exitCode, string packagesPath)
{
var exitCodeCopy = exitCode;
var pythonPath = packagesPath + "\\..\\python.exe";
var index_url = get_index_url();
var pythonPath = Path.Combine(Directory.GetParent(packagesPath)?.ToString() ?? string.Empty, "Scripts");
#if UNITY_EDITOR_WIN
var task = Task.Run(() => ExecuteCmd($"\"{pythonPath}\" -m pip install --upgrade --no-warn-script-location unity-cv-datasetvisualizer\"{index_url}\"", ref exitCodeCopy));
var task = Task.Run(() => ExecuteCmd($"cd {pythonPath} && pip uninstall -y unity-cv-datasetvisualizer", ref exitCodeCopy));
#elif UNITY_EDITOR_OSX
var task = Task.Run(() => ExecuteCmd($"cd \'{packagesPath}\'; ./python3.7 -m pip install --upgrade unity-cv-datasetvisualizer \'{index_url}'", ref exitCodeCopy));
var task = Task.Run(() => ExecuteCmd($"cd {packagesPath}; ./python3.7 pip uninstall unity-cv-datasetvisualizer", ref exitCodeCopy));
#endif
exitCode = exitCodeCopy;
return task;
}

// return the internal artifactory index url if using the internal perception package
static String get_index_url()
static string GetIndexURL()
{
var pckName = "com.unity.perception.internal";
if ( !File.Exists("Packages/manifest.json") )
return "";
string jsonText = File.ReadAllText("Packages/manifest.json");
var hasPerceptionInternal = jsonText.Contains( pckName );
if (hasPerceptionInternal)
const string pckName = "com.unity.perception.internal";
if (!File.Exists("Packages/manifest.json"))
{
return " --index-url=https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/unity-pypi-local/simple/";
return string.Empty;
}
return "";

var jsonText = File.ReadAllText("Packages/manifest.json");
var hasPerceptionInternal = jsonText.Contains( pckName );
return hasPerceptionInternal ? "--index-url=https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/unity-pypi-local/simple/" : string.Empty;
}

// ReSharper disable Unity.PerformanceAnalysis
Expand Down Expand Up @@ -117,8 +131,12 @@ static async Task SetupVisualizer()

EditorUtility.DisplayProgressBar("Setting up the Visualizer", "Installing Visualizer (This may take a few minutes)", 2f / steps);

await InstallationCommand(ref exitCode, packagesPath);

await InstallationCommand(ref exitCode, packagesPath, false);
if (exitCode != 0)
{
Debug.LogWarning("Installing Public Visualizer");
await InstallationCommand(ref exitCode, packagesPath, true);
}
if (exitCode != 0)
{
EditorUtility.ClearProgressBar();
Expand Down Expand Up @@ -231,7 +249,7 @@ public static async Task RunVisualizer(string project)
{
await SetupVisualizer();
}

var lastDataPath = GetLastDataPath();
var (pythonPid, port, visualizerPid) = ReadEntry(lastDataPath);

Expand Down Expand Up @@ -349,7 +367,7 @@ static void ExecuteVisualizer(string project)
#elif UNITY_EDITOR_OSX
var packagesPath = project.Replace("/Assets","/Library/PythonInstall/bin");
#endif

var pathToData = GetLastDataPath();
#if UNITY_EDITOR_WIN
packagesPath = packagesPath.Replace("/", "\\");
Expand All @@ -369,7 +387,7 @@ static void ExecuteVisualizer(string project)
Debug.LogError("Failed launching the visualizer - Exit Code: " + exitCode);
}
}

static string GetLastDataPath()
{
var lastEndpointType = PlayerPrefs.GetString(SimulationState.lastEndpointTypeKey, string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public interface IFileSystemEndpoint
/// </summary>
string defaultPathToken { get; }

/// <summary>
/// The default path to user if a user does not set a custom storage directory
/// </summary>
string defaultPath { get; }

/// <summary>
/// The runtime directory that the dataset will be written to.
/// This directory may be different from the <see cref="basePath"/> in cases where the <see cref="basePath"/>
Expand Down
Loading

0 comments on commit 4deadb5

Please sign in to comment.