Problem in using a code that makes use of PyTorch Encoding package

Please also check here:
After I install the repo using:

$ pip install .

and run my code, I get the following error:

    Running setup.py install for torch-encoding ... done
Successfully installed Pillow-8.1.0 certifi-2020.12.5 chardet-4.0.0 idna-2.10 nose-1.3.7 portalocker-2.2.0 requests-2.25.1 scipy-1.6.0 torch-encoding-1.2.2b20210129 torchvision-0.8.2 tqdm-4.56.0 urllib3-1.26.3
(torchenc) mona@goku:~/research/code/PyTorch-Encoding$ python test_demo.py 
Traceback (most recent call last):
  File "test_demo.py", line 2, in <module>
    import encoding
  File "/home/mona/research/code/PyTorch-Encoding/encoding/__init__.py", line 12, in <module>
    from .version import __version__
ModuleNotFoundError: No module named 'encoding.version'



This is the test_demo.py code:

import torch
import encoding

# Get the model
model = encoding.models.get_model('DeepLab_ResNeSt269_PContext', pretrained=True).cuda()
model.eval()

# Prepare the image
url = 'https://github.com/zhanghang1989/image-data/blob/master/' + \
      'encoding/segmentation/pcontext/2010_001829_org.jpg?raw=true'
filename = 'example.jpg'
img = encoding.utils.load_image(encoding.utils.download(url, filename)).cuda().unsqueeze(0)

# Make prediction
output = model.evaluate(img)
predict = torch.max(output, 1)[1].cpu().numpy() + 1

# Get color pallete for visualization
mask = encoding.utils.get_mask_pallete(predict, 'pascal_voc')
mask.save('output.png')

Can you please guide how to fix it?

Here are my pip freeze results. I am aware of ninja: build stopped: subcommand failed. · Issue #162 · zhanghang1989/PyTorch-Encoding · GitHub but I am hoping we can make this work for the newer versions of packages.

$ pip freeze
certifi==2020.12.5
chardet==4.0.0
idna==2.10
nose==1.3.7
numpy==1.19.5
Pillow==8.1.0
portalocker==2.2.0
requests==2.25.1
scipy==1.6.0
torch==1.7.1
torch-encoding==1.2.2b20210129
torchvision==0.8.2
tqdm==4.56.0
typing-extensions==3.7.4.3
urllib3==1.26.3

mona@goku:~$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
$ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

$ lsb_release -a
LSB Version:	core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal

The error is raised by import encoding, which seems to be a custom script in your repository, so you would have to make sure it’s able to import all modules in its __init__.py.

1 Like

Thank you. I moved it to home dir and worked.