-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Export Tensorflow SavedModel? #2991
Comments
Thank you for your comments. We’ve documented your feedback and will prioritize when appropriate. |
also - opening this up as a more general discussion to see if folks in the community have attempted to do what you are describing above. |
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: |
This issue has been automatically marked as stale because it has not had activity in the last 14 days. It will be closed in the next 14 days if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had activity in the last 28 days. If this issue is still valid, please ping a maintainer. Thank you for your contributions. |
@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 Here is a model trained in Unity, then exported as a Tensorflow SavedModel, converted for use with Tensorflow.js, and loaded in a javascript sketch: https://www.aidanjnelson.com/balance-ball/ Thoughts? |
hi @AidanNelson - quick question for you. Can you describe a use case where you would want to run an ML-Agents model via Tensorflow.js? Barracuda allows for ML-Agents models to be run in WebGL games. |
Sure! 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. Teachers teaching Javascript (in a middle or high school environment, for instance) with the ability to incorporate a simple RL model into their curriculum would be able to:
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. Any thoughts? |
Hi @AidanNelson - it feels like ML-A + Unity would not be a good solution for what you are describing (teaching Javascript with a small RL component). I think there may be more straightforward examples like uploading a picture and doing some image classification. However, let me know if I am missing some additional context. |
@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. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi There,
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
I would like to be able to export a trained model from Unity in one of the above Tensorflow formats (SavedModel, Keras model, or TensorFlow Hub module), for later conversion to Tensorflow.js using existing solutions.
I see that in the current release of ML-Agents, Barracuda is used to store models, and that a Tensorflow to Barracuda conversion script exists, but am unsure how possible it would be to convert a model from Barracuda back to Tensorflow and the extent of this work.Any information about this would be most appreciated!
Aidan
A (vaguely) related issue:
#1802
UPDATE (2019.12.2)
I looked further and realized that Unity Ml-Agents still uses Tensorflow for training, and only converts the models to Barracuda '.nn' files on export for inference. Now I am trying to figure out how to export a SavedModel format in this export_model function, for later conversion to TFJS-capable model. Does anyone have experience with using the saved model builder and a sense for how it could be implemented here? I've altered the export_model function to use
tf.compat.v1.saved_model.Builder
in the following code:This runs without error, but produces a SavedModel without any Signature Definitions, as seen when I run the
python saved_model_cli.py show --dir ./ --all
as per this: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!
Thanks again.
The text was updated successfully, but these errors were encountered: