Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLA-345] float visual observations #3148

Merged
merged 9 commits into from
Jan 7, 2020
Merged

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Jan 3, 2020

Support uncompressed visual (i.e. 3d float arrays) observations. This required a small change in how we set up the WriteAdapter on the c# side (to allow passing the shape).

Also added a unit test showing how to go from a 2D float array to an observation.

- target: {fileID: 4124767863011510, guid: 5c2bd19e4bbda4991b74387ca5d28156, type: 2}
- target: {fileID: 1488387672112076, guid: 5c2bd19e4bbda4991b74387ca5d28156, type: 3}
propertyPath: m_Name
value: FloatAgent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change one of the prefab instances to have a different name and compression type.

def test_process_pixels():
in_array = np.random.rand(128, 128, 3)
in_array = np.random.rand(128, 64, 3)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made these non-square. Fortunately no errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

@@ -119,27 +118,6 @@ def __init__(
self.agents = agents
self.action_masks = action_mask

@staticmethod
@timed
def process_pixels(image_bytes: bytes, gray_scale: bool) -> np.ndarray:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was identical to the rpc_utils version. It now calls the new rpc_utils method.

@chriselion chriselion marked this pull request as ready for review January 3, 2020 01:33

namespace MLAgents.Tests
{
public class Float2DSensor : ISensor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably usable on its own, but I can't think of a good usecase in our current examples. It would be cool to use for occupancy maps (see https://www.gdcvault.com/play/1267/(307)-Beyond-Behavior-An-Introduction starting around 13:00)

Copy link
Contributor Author

@chriselion chriselion Jan 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move it out of tests and to a fully-supported component when we make a hide-and-seek demo.

UnitySDK/Assets/ML-Agents/Scripts/Sensor/WriteAdapter.cs Outdated Show resolved Hide resolved
UnitySDK/Assets/ML-Agents/Scripts/Sensor/WriteAdapter.cs Outdated Show resolved Hide resolved
def test_process_pixels():
in_array = np.random.rand(128, 128, 3)
in_array = np.random.rand(128, 64, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

);

// Math copied from TensorShape.Index(). Note that m_Batch should always be 0
var index = m_Batch * height * width * channels + h * width * channels + w * channels + ch;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we don't use TensorShape instead of int[]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it's a bit less user-friendly than int[] because you have to pass 1 to the batch size for our usage. It would also prevent us from using higher-dimensional observations (although I guess we wouldn't be able to run inference on that either). Plus I didn't know about it at the time :)

I can take a stab at swapping in a separate PR - we could use TensorShape in the ISensor interface, but use int[] in the slightly-higher-level SensorBase interface.

https://github.cds.internal.unity3d.com/unity/UnityInferenceEngine/blob/master/UnityProject/Assets/Barracuda/Core/Tensor.cs#L35

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. My thoughts (which I didn't fully articulate) were that int[] would still be on the public interface of this, but could use TensorShape internally for things like computing the index. Maybe it's a bit of overkill.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, not a requirement for this to get merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let me try it in another PR.

Copy link
Contributor

@surfnerd surfnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just have that one question of why we aren't using TensorShape instead of int[] inside of Sensor.

@chriselion chriselion merged commit 5102adb into master Jan 7, 2020
@delete-merged-branch delete-merged-branch bot deleted the develop-MLA-345-float-visual branch January 7, 2020 00:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants