Transferring TensorFlow models in Jetson nao 4GB

Hi Everyone, I’m training a pytorch reinforcement learning model in a donkeycar simulator and want to use the trained model to drive my Jetson nano robot car. I’m looking for a procedure to use the resulting pytorch .zip model in Jetson nano 4GB robot car, if someone can help. Also, is there any requirement other than aligning the Tensorflow version between the two domains (simulation vs. real car)? I’m using JetPack 4.5.1, Python 3.6.9, and TensorfLOW 2.5 in my Jetson nano. Further upgrade is not an option.

Hi,

Do you want to deploy the PyTorch model on the Jetson Nano?
If so, you can install PyTorch on Nano directly.

Thanks.

Hi,
Yes, I have Pytorch installed in my 4.5.1 Jetson nano:

(env) jetson@nano-4gb-jp451:~$ python3 -c “import torch; print(torch.version)”
1.10.0

However when I run:

(env) jetson@nano-4gb-jp451:~$ python3 mycar/manage.py drive --model projects/vec_model/best_model_extracted/

I got the error:

INFO:donkeycar.parts.keras:Created KerasLinear with interpreter: KerasInterpreter
ERR>> Unknown extension type on model file!!
GST_ARGUS: Cleaning up
Segmentation fault (core dumped)

best_model_extracted folder includes the following files:
data policy.optimizer.pth policy.pth pytorch_variables.pth _stable_baselines3_version system_info.txt

But looks the Donkeycar manage.py script expect another format.

Strangely, when I looked into manage.py, I found this piece of code:

    if '.h5' in model_path or '.trt' in model_path or '.tflite' in \
            model_path or '.savedmodel' in model_path or '.pth':
        # load the whole model with weigths, etc
        load_model(kl, model_path)

So, not sure why I got the above error?

Any guide on how to run Pytorch models in Jetson nano?

BR

Hi,

Which PyTorch version do you use for training?
If the versions are different, the model might not be compatible.

Thanks.

Hi,

The following versions are in use:

PC:
PyTorch version: 2.7.1
Tensorflow version: 2.15.1
Python: 3.11.13

Jetson Nano:
PyTorch version: 1.10.0
Tensorflow version: 2.5.0
Python: 3.6.9

I tried to align both PyTorch and Tensorflow versions between the PC and Jetson nano, but failed as 2.5.0 is an old TF version.

I also tried to create virtual environments with python 3.9 and 3.8 to support this old version of TF, but no luck! Lots of dependencies were broken when installing the donkeycar.

Any idea how to address this situation?

BR

Hi,

Are you able to align the version with the container?
For example, running an older Ubuntu container on the desktop and installing the corresponding version.

If not, another alternative is to export the model into a portable format, like ONNX.

Thanks.

Hi,

I actually went for an older python 3.7 version:
conda create -n donkey_py3.7 python=3.7

I made sure to align this environment with what in Jetson nano (mainly, stable_baselines3 and pytorch). However, that didn’t help to resolve the model-loading issue. It looks DonkeyCar doesn’t support the direct loading of Pytorch models. So, I had to create a customized loader and edit the manage.py file as a workaround.

And, sorry! I should have give it a correct title: Transferring Pytorch models to Jetson nano

Thanks for your support!