GitHub
4 年前
当前提交
1cc30d75
共有 31 个文件被更改,包括 240 次插入 和 192 次删除
-
4Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/SensorBase.cs
-
4Project/Assets/ML-Agents/TestScenes/TestCompressedTexture/TestTextureSensor.cs
-
14com.unity.ml-agents.extensions/Runtime/Match3/Match3Sensor.cs
-
4com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs
-
4com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsBodySensor.cs
-
8com.unity.ml-agents.extensions/Tests/Editor/Match3/Match3SensorTests.cs
-
5com.unity.ml-agents/CHANGELOG.md
-
2com.unity.ml-agents/Runtime/Analytics/Events.cs
-
42com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
-
2com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
-
4com.unity.ml-agents/Runtime/Sensors/BufferSensor.cs
-
4com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs
-
24com.unity.ml-agents/Runtime/Sensors/ISensor.cs
-
4com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
-
4com.unity.ml-agents/Runtime/Sensors/Reflection/ReflectionSensorBase.cs
-
4com.unity.ml-agents/Runtime/Sensors/RenderTextureSensor.cs
-
27com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs
-
4com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs
-
34com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs
-
4com.unity.ml-agents/Tests/Editor/Inference/ParameterLoaderTest.cs
-
4com.unity.ml-agents/Tests/Runtime/Sensor/FloatVisualSensorTests.cs
-
4com.unity.ml-agents/Tests/Runtime/Sensor/SensorShapeValidatorTests.cs
-
19com.unity.ml-agents/Tests/Runtime/Sensor/StackingSensorTests.cs
-
4com.unity.ml-agents/Tests/Runtime/Utils/TestClasses.cs
-
23docs/Migrating.md
-
109com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs
-
3com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs.meta
-
30com.unity.ml-agents/Tests/Runtime/Sensor/CompressionSpecTests.cs
-
3com.unity.ml-agents/Tests/Runtime/Sensor/CompressionSpecTests.cs.meta
-
20com.unity.ml-agents/Runtime/Sensors/ISparseChannelSensor.cs
-
11com.unity.ml-agents/Runtime/Sensors/ISparseChannelSensor.cs.meta
|
|||
using System.Linq; |
|||
namespace Unity.MLAgents.Sensors |
|||
{ |
|||
/// <summary>
|
|||
/// The compression setting for visual/camera observations.
|
|||
/// </summary>
|
|||
public enum SensorCompressionType |
|||
{ |
|||
/// <summary>
|
|||
/// No compression. Data is preserved as float arrays.
|
|||
/// </summary>
|
|||
None, |
|||
|
|||
/// <summary>
|
|||
/// PNG format. Data will be stored in binary format.
|
|||
/// </summary>
|
|||
PNG |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// A description of the compression used for observations.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Most ISensor implementations can't take advantage of compression,
|
|||
/// and should return CompressionSpec.Default() from their ISensor.GetCompressionSpec() methods.
|
|||
/// Visual observations, or mulitdimensional categorical observations (for example, image segmentation
|
|||
/// or the piece types in a match-3 game board) can use PNG compression reduce the amount of
|
|||
/// data transferred between Unity and the trainer.
|
|||
/// </remarks>
|
|||
public struct CompressionSpec |
|||
{ |
|||
internal SensorCompressionType m_SensorCompressionType; |
|||
|
|||
/// <summary>
|
|||
/// The compression type that the sensor will use for its observations.
|
|||
/// </summary>
|
|||
public SensorCompressionType SensorCompressionType |
|||
{ |
|||
get => m_SensorCompressionType; |
|||
} |
|||
|
|||
internal int[] m_CompressedChannelMapping; |
|||
|
|||
/// The mapping of the channels in compressed data to the actual channel after decompression.
|
|||
/// The mapping is a list of integer index with the same length as
|
|||
/// the number of output observation layers (channels), including padding if there's any.
|
|||
/// Each index indicates the actual channel the layer will go into.
|
|||
/// Layers with the same index will be averaged, and layers with negative index will be dropped.
|
|||
/// For example, mapping for CameraSensor using grayscale and stacking of two: [0, 0, 0, 1, 1, 1]
|
|||
/// Mapping for GridSensor of 4 channels and stacking of two: [0, 1, 2, 3, -1, -1, 4, 5, 6, 7, -1, -1]
|
|||
public int[] CompressedChannelMapping |
|||
{ |
|||
get => m_CompressedChannelMapping; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Return a CompressionSpec indicating possible compression.
|
|||
/// </summary>
|
|||
/// <param name="sensorCompressionType">The compression type to use.</param>
|
|||
/// <param name="compressedChannelMapping">Optional mapping mapping of the channels in compressed data to the
|
|||
/// actual channel after decompression.</param>
|
|||
public CompressionSpec(SensorCompressionType sensorCompressionType, int[] compressedChannelMapping = null) |
|||
{ |
|||
m_SensorCompressionType = sensorCompressionType; |
|||
m_CompressedChannelMapping = compressedChannelMapping; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Return a CompressionSpec indicating no compression. This is recommended for most sensors.
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public static CompressionSpec Default() |
|||
{ |
|||
return new CompressionSpec |
|||
{ |
|||
m_SensorCompressionType = SensorCompressionType.None, |
|||
m_CompressedChannelMapping = null |
|||
}; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Return whether the compressed channel mapping is "trivial"; if so it doesn't need to be sent to the
|
|||
/// trainer.
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
internal bool IsTrivialMapping() |
|||
{ |
|||
var mapping = CompressedChannelMapping; |
|||
if (mapping == null) |
|||
{ |
|||
return true; |
|||
} |
|||
// check if mapping equals zero mapping
|
|||
if (mapping.Length == 3 && mapping.All(m => m == 0)) |
|||
{ |
|||
return true; |
|||
} |
|||
// check if mapping equals identity mapping
|
|||
for (var i = 0; i < mapping.Length; i++) |
|||
{ |
|||
if (mapping[i] != i) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0ddff1d1b7ad4170acb1a10272d4a8c2 |
|||
timeCreated: 1616006929 |
|
|||
using NUnit.Framework; |
|||
using Unity.MLAgents.Sensors; |
|||
|
|||
namespace Unity.MLAgents.Tests |
|||
{ |
|||
[TestFixture] |
|||
public class CompressionSpecTests |
|||
{ |
|||
[Test] |
|||
public void TestIsTrivialMapping() |
|||
{ |
|||
Assert.IsTrue(CompressionSpec.Default().IsTrivialMapping()); |
|||
|
|||
var spec = new CompressionSpec(SensorCompressionType.PNG, null); |
|||
Assert.AreEqual(spec.IsTrivialMapping(), true); |
|||
|
|||
spec = new CompressionSpec(SensorCompressionType.PNG, new[] { 0, 0, 0 }); |
|||
Assert.AreEqual(spec.IsTrivialMapping(), true); |
|||
|
|||
spec = new CompressionSpec(SensorCompressionType.PNG, new[] { 0, 1, 2, 3, 4 }); |
|||
Assert.AreEqual(spec.IsTrivialMapping(), true); |
|||
|
|||
spec = new CompressionSpec(SensorCompressionType.PNG, new[] { 1, 2, 3, 4, -1, -1 }); |
|||
Assert.AreEqual(spec.IsTrivialMapping(), false); |
|||
|
|||
spec = new CompressionSpec(SensorCompressionType.PNG, new[] { 0, 0, 0, 1, 1, 1 }); |
|||
Assert.AreEqual(spec.IsTrivialMapping(), false); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cd0990de0eb646b0b0531b91c840c9da |
|||
timeCreated: 1616030728 |
|
|||
namespace Unity.MLAgents.Sensors |
|||
{ |
|||
/// <summary>
|
|||
/// Sensor interface for sparse channel sensor which requires a compressed channel mapping.
|
|||
/// </summary>
|
|||
public interface ISparseChannelSensor : ISensor |
|||
{ |
|||
/// <summary>
|
|||
/// Returns the mapping of the channels in compressed data to the actual channel after decompression.
|
|||
/// The mapping is a list of interger index with the same length as
|
|||
/// the number of output observation layers (channels), including padding if there's any.
|
|||
/// Each index indicates the actual channel the layer will go into.
|
|||
/// Layers with the same index will be averaged, and layers with negative index will be dropped.
|
|||
/// For example, mapping for CameraSensor using grayscale and stacking of two: [0, 0, 0, 1, 1, 1]
|
|||
/// Mapping for GridSensor of 4 channels and stacking of two: [0, 1, 2, 3, -1, -1, 4, 5, 6, 7, -1, -1]
|
|||
/// </summary>
|
|||
/// <returns>Mapping of the compressed data</returns>
|
|||
int[] GetCompressedChannelMapping(); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 63bb76c1e31c24fa5b4a384ea0edbfb0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue