Export Tensorflow SavedModel? #2991
I am exploring the possibility of training a model in Unity using the ML-Agents package, then exporting that model for use with Tensorflow.js in the browser. Eventually, I'd like to incorporate that model into ml5.js, an approachable wrapper library around tf.js. I think this workflow would be an exciting use of the training / curriculum learning structure of Unity, and allow people to create models which could be used in online demonstrations of reinforcement learning (...or maybe agent-based AI for online games?)
Currently, it is possible to convert Tensorflow models for use with Tensorflow.js as long as they are in the SavedModel, Keras model, or TensorFlow Hub module format.
Describe the solution you'd like
Any information about this would be most appreciated!
A (vaguely) related issue:
This runs without error, but produces a SavedModel without any Signature Definitions, as seen when I run the
This then throws an error when converting to TFJS using the tfjs-converter:
along with many warnings like this:
If anyone can shed light on how to include SignatureDefs in the exported model, and export a valid SavedModel from Unity ML-Agents, that would be awesome!
The text was updated successfully, but these errors were encountered:
For anyone trying to use models from Unity in TensorFlow.js, here is the approach I took.
If anyone can clarify the different output nodes:
@unityjeffrey I would love to open this thread up again now that MLAgents is in an official release.
The ability to export models as Tensorflow
Part of what is great about the Unity ML-Agents Framework is the ability to quickly spin up a training environment and get started experimenting with RL without a deep knowledge of the difference between SAC and PPO or the ability to tune the various training hyperparameters. ML-Agents provides an easier (and more powerful) access point to training RL than I've seen elsewhere, in an environment which many people are already familiar with. That said, there are a number of contexts in which someone might want the final version of their project to exist online outside of a Unity WebGL build. The first one that comes to mind is a classroom environment.
Personally, I want to work with incorporating models into projects using p5.js and ml5.js, libraries which have large and welcoming communities around them and are specifically geared towards accessibility and education.
@unityjeffrey - You're definitely right that there are examples of browser-based ML which are more straightforward to implement. Image Classification, doodle classifiers, etc. are all available as part of ml5.js or TFJS directly and very easy to implement. From a student perspective, however, reinforcement learning presents a really valuable opportunity for learning ML because an 'agent' whose actions are being controlled by an RL brain is a much more visible analogy than traditional ML 'Hello World' projects. What I mean is that the 'decision making' process happens in real time and happens over time. Rather than being presented with a single input and an output, we are presented with a continuous series of inputs and outputs, which, taken in aggregate, seems to form the 'behavior' of an agent. Because of this, RL is also more fun!
Reinforcement Learning has (up until now) been quite challenging to implement in the browser.
ML-Agents could really lower the barrier to entry for teaching about RL, and I think interoperability with TFJS would help that.
I think this is just one of numerous places where having a Unity-trained RL model in the browser (outside of a WebGL build) would be exciting and fun. I am happy to brainstorm others (the first one that comes to mind is having an agent interact directly with DOM elements) if it would be helpful for this feature-request / discussion.