Pi 4 - Pytorch - Segmentation Fault

November 2, 2023, 06:22

erencode

Hi there, I built a machine learning model that detects licenses plates. Everything is working fine on my main laptop machine, but as soon as I try runningit on the PI and try passing the tensor into the first convolutional layer I get a "Segmentation Fault" error. Happy to provide any information that wil help debug this!

erencode

i've already verified the packages are the same as on my laptop. the python version is the same

erencode

i've added print statements to see exactly where the segmentation fault is occuring, and it is exactly on the line:
py
t = self.conv1(t)

erencode

the tensor has the correct size and channels as well

erencode

i trained the model on my main laptop using a GPU and torch cuda, and then saved the model as a .pth. the model is being loaded perfectly fine on the rasberry pi as well

erencode

the model is made up of 5 convolutional layers and 3 fully connected or linear layers

erencode

i've tried viewing task manager while running the code on the pi, and it doesn't max out cpu or memory usage. I've also checked with htop and it doesn't max out the cpu or mem there either

oops.se

A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system). And without code or any other tangible info... Its a guessing game. So add debugging : https://www.geeksforgeeks.org/python-debugger-python-pdb/

erencode

i've stepped through with pdb, and can see where the seg fault occurs more accurately now I think

erencode

its apparently here: return F.conv2d(input, weight, bias, self.stride, inside the file: 'home/pi/.local/lib/python3.9/site-packages/torch/nn/modules/conv.py(456)_conv_forward()

erencode

exact output is:
(pdb)
> home/pi/.local/lib/python3.9/site-packages/torch/nn/modules/conv.py(456)_conv_forward()
-> return F.conv2d(input, weight, bias, self.stride,
(pdb)
Segmentation fault