Segmentation fault with torchvision.transforms.ToTensor() in streamlit app

My Device: Mac m1 pro
Environment:
Streamlit==1.21.1
torch==1.11.0 (I tried 2.0.0 but it failed, someone suggest to downgrade but still doesn’t work)
torchvision==0.12.0
numpy==1.23.5

content_transform = transforms.Compose([
        transforms.Resize([224, 224]),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
    ])
# img: PIL.Image
img = content_transform(img)

After utilizing pdb.set_trace for debugging purposes, I determined that the segmentation fault was caused by the code located within transforms.ToTensor() .

img = img.permute((2, 0, 1)).contiguous()

I am unable to identify the cause of the issue and would appreciate any assistance in resolving it.

  • This problem occurs on your local Mac machine?
  • The problem seems to be unrelated to streamlit, so it would make more sense to ask in the pytorch forum, search in the pytorch issues or write a new pytorch issue?

While PyTorch appears to be functioning properly in isolation within the current environment, it seems to be causing the streamlit app to crash when I try to integrate it.

Reinstall streamlit, PyTorch, Torchvision solve the problem

conda install -c conda-forge streamlit
conda install pytorch torchvision torchaudio -c pytorch

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.