You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/export.rst
+154-7Lines changed: 154 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,16 +29,15 @@ to do inference in another framework.
29
29
30
30
31
31
Export to ONNX
32
-
-----------------
32
+
--------------
33
33
34
34
35
35
If you are using PyTorch 2.0+ and ONNX Opset 14+, you can easily export SB3 policies using the following code:
36
36
37
37
38
38
.. warning::
39
39
40
-
The following returns normalized actions and doesn't include the `post-processing <https://github.com/DLR-RM/stable-baselines3/blob/a9273f968eaf8c6e04302a07d803eebfca6e7e86/stable_baselines3/common/policies.py#L370-L377>`_ step that is done with continuous actions
41
-
(clip or unscale the action to the correct space).
40
+
The following returns normalized actions and doesn't include the `post-processing <https://github.com/DLR-RM/stable-baselines3/blob/a9273f968eaf8c6e04302a07d803eebfca6e7e86/stable_baselines3/common/policies.py#L370-L377>`_ step that is done with continuous actions (clip or unscale the action to the correct space).
42
41
43
42
44
43
.. code-block:: python
@@ -192,11 +191,159 @@ There is a draft PR in the RL Zoo about C++ export: https://github.com/DLR-RM/rl
192
191
action_jit = loaded_module(dummy_input)
193
192
194
193
195
-
Export to tensorflowjs / ONNX-JS
196
-
--------------------------------
194
+
Export to ONNX-JS / ONNX Runtime Web
195
+
------------------------------------
197
196
198
-
TODO: contributors help is welcomed!
199
-
Probably a good starting point: https://github.com/elliotwaite/pytorch-to-javascript-with-onnx-js
197
+
Official documentation: https://onnxruntime.ai/docs/tutorials/web/build-web-app.html
198
+
199
+
Full example code: https://github.com/JonathanColetti/CarDodgingGym
As of November 2025, `onnx2tf <https://github.com/PINTO0309/onnx2tf>`_ does not support TensorFlow.js. Therefore, `tfjs-converter <https://github.com/tensorflow/tfjs-converter>`_ is used instead. However, tfjs-converter is not currently maintained and requires older opsets and TensorFlow versions.
273
+
274
+
275
+
In order for this to work, you have to do multiple conversions: SB3 => ONNX => TensorFlow => TensorFlow.js.
276
+
277
+
The opset version needs to be changed for the conversion (``opset_version=14`` is currently required). Please refer to the code above for more stable usage with a higher opset.
278
+
279
+
The following is a simple example that showcases the full conversion + inference.
280
+
281
+
Please refer to the previous sections for the first step (SB3 => ONNX).
282
+
The main difference is that you need to specify ``opset_version=14``.
Copy file name to clipboardExpand all lines: docs/misc/changelog.rst
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ Bug Fixes:
19
19
- Fixed env checker to properly handle ``Sequence`` observation spaces when nested inside composite spaces (``Dict``, ``Tuple``, ``OneOf``) (@copilot)
20
20
- Update env checker to warn users when using Graph space (@dhruvmalik007).
21
21
- Fixed memory leak in ``VecVideoRecorder`` where ``recorded_frames`` stayed in memory due to reference in the moviepy clip (@copilot)
22
+
- Remove double space in `StopTrainingOnRewardThreshold` callback message (@sea-bass)
22
23
23
24
`SB3-Contrib`_
24
25
^^^^^^^^^^^^^^
@@ -42,6 +43,11 @@ Documentation:
42
43
- Documented Atari wrapper reset behavior where ``env.reset()`` may perform a no-op step instead of truly resetting when ``terminal_on_life_loss=True`` (default), and how to avoid this behavior by setting ``terminal_on_life_loss=False``
43
44
- Clarified comment in ``_sample_action()`` method to better explain action scaling behavior for off-policy algorithms (@copilot)
44
45
- Added sb3-plus to projects page
46
+
- Added example usage of ONNX JS
47
+
- Updated link to paper of community project DeepNetSlice (@AlexPasqua)
48
+
- Added example usage of Tensorflow JS
49
+
- Included exact versions in ONNX JS and example project
50
+
- Made step 2 (`pip install`) of `CONTRIBUTING.md` more robust
|Paper: **under review** (citation instructions on the project's README.md) -> see this Master's Thesis for the moment: https://etd.adm.unipi.it/theses/available/etd-01182023-110038/unrestricted/Tesi_magistrale_Pasquali_Alex.pdf
0 commit comments