# How to save weights in tensorflow's form?

**URL:** <https://discuss.ray.io/t/how-to-save-weights-in-tensorflows-form/3101>\
**Category:** RLlib\
**Created:** [August 1, 2021, 11:29am UTC](https://discuss.ray.io/t/how-to-save-weights-in-tensorflows-form/3101 "2021-08-01T11:29:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavin](https://avatars.discourse-cdn.com/v4/letter/g/439d5e/32.png) [@gavin](https://discuss.ray.io/u/gavin)\
**Post date:** [August 1, 2021, 11:29am UTC](https://discuss.ray.io/t/how-to-save-weights-in-tensorflows-form/3101/1 "2021-08-01T11:29:13Z")

</div>

Hello everyone!

I am working on flow, a computational framework for reinforcement learning in traffic control, which is developed by Berkeley too. In the tutorial, i have already known that the trained neural network models’ parameter can be saved into a ray[rllib] form and rerun by the following code:

```auto
trials = run_experiments({
    flow_params["exp_tag"]: {
        "run": alg_run,
        "env": gym_name,
        "config": {
            **config
        },
        "restore": "/ray_results/experiment/dir/checkpoint_50/checkpoint-50"
        "checkpoint_freq": 1,
        "checkpoint_at_end": True,
        "max_failures": 999,
        "stop": {
            "training_iteration": 1,
        },
    },
})

```

By running this code, i can restart from a checkpoint and continue transfer learning.  
However, i am wondering if i can save the weights in a tensorflow’s form so that i can use the model in other simulator (environment).

Thank you! 👀

---

<div class="post-metadata">

**Author:** ![mannyv](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mannyv/32/606_2.png) [@mannyv](https://discuss.ray.io/u/mannyv)\
**Post date:** [August 1, 2021, 12:14pm UTC](https://discuss.ray.io/t/how-to-save-weights-in-tensorflows-form/3101/2 "2021-08-01T12:14:30Z")

</div>

Hi @gavin,

Welcome to the forums. I think calling either `export_policy_model` on the trainer or `export_model` model on the policy should do the trick for you. There is an option in those methods to get the model in onnx format. Here is the export\_model method for tf.

> <https://github.com/ray-project/ray/blob/6703091cdc9f440c886c8c33029bfd5631814c29/rllib/policy/tf_policy.py#L551>

* * *

> **[Manny V is helping people do cool things with RL](https://www.buymeacoffee.com/mannyv)**
>
> Hey, so glad we got to connect. If you found my suggestions useful feel free to buy me a coffee!

---

<div class="post-metadata">

**Author:** ![gavin](https://avatars.discourse-cdn.com/v4/letter/g/439d5e/32.png) [@gavin](https://discuss.ray.io/u/gavin)\
**Post date:** [August 1, 2021, 2:55pm UTC](https://discuss.ray.io/t/how-to-save-weights-in-tensorflows-form/3101/3 "2021-08-01T14:55:11Z")

</div>

Appreciate your answer! 🤩
