NVIDIA-AI-IOT / jetbot

An educational AI robot based on NVIDIA Jetson Nano.
MIT License
2.97k stars 1.02k forks source link

Collision avoidance issue: name 'torch' is not defined #331

Closed Comicboy closed 2 years ago

Comicboy commented 3 years ago

Hi everyone!

I’m trying to go through the collision avoidance notebook, which I acces through the jupyterlab server running on the Nano (just like stated in the setup tutorial).

Everything worked just fine until I got to the live_demo_resnet18.ipynb notebook. I can run the first two cells in the notebook and load in my trained model with torch, but when I get to the third cell, which is:

device = torch.device(‘cuda’)
model = model.to(device)
model = model.eval().half()

I get the following error message:
NameErrorTraceback (most recent call last)
in
----> 1 device = torch.device(‘cuda’)
2 model = model.to(device)
3 model = model.eval().half()
NameError: name ‘torch’ is not defined

Which I can’t understand, because I get that it means that either torch is not installed or it isn’t imported into the script, but since torch is installed on the Nano (I can import it from the command line on the device) and it is imported into the script in the very first cell of this notebook…I truly feel myself a bit lost.

I noticed something, which can be important in solving my problem, after I execute the second cell of the notebook, which is:

model.load_state_dict(torch.load('best_model_resnet18.pth'))

the kernel says Busy -> Restarting -> Idle which is quite strange I don’t understand why does it need to restart. Perhaps that’s the point where it forgets that torch was already imported into the script? If this is the case how can I prevent it from restarting?

I’m using the JP 4.4.1 SDK

Thanks in advance!

tokk-nv commented 3 years ago

Hello Comicboy,

This looks like the memory is running out and the python kernel restarted. (You may have noticed the execution number on the cell got reset to 1)

The easiest solution would be to enable a swap file. You can execute this script on your jetson. (Docker host side, if you are using Docker, not within the container. Or you can also use a tool like this to help you create the swap file. https://github.com/rbonghi/jetson_stats