Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'cpu' #405

Open
szy4017 opened this issue Sep 8, 2021 · 2 comments
Open

ImportError: cannot import name 'cpu' #405

szy4017 opened this issue Sep 8, 2021 · 2 comments

Comments

@szy4017
Copy link

szy4017 commented Sep 8, 2021

Traceback (most recent call last):
File "scripts/prepare_pascal.py", line 6, in
from encoding.utils import download, mkdir
File "/home/szy/PyTorch-Encoding/encoding/init.py", line 13, in
from . import nn, functions, parallel, utils, models, datasets, transforms
File "/home/szy/PyTorch-Encoding/encoding/nn/init.py", line 12, in
from .encoding import *
File "/home/szy/PyTorch-Encoding/encoding/nn/encoding.py", line 18, in
from ..functions import scaled_l2, aggregate, pairwise_cosine
File "/home/szy/PyTorch-Encoding/encoding/functions/init.py", line 2, in
from .encoding import *
File "/home/szy/PyTorch-Encoding/encoding/functions/encoding.py", line 15, in
from encoding import cpu
ImportError: cannot import name 'cpu'

When I run this command 'python scripts/prepare_ade20k.py' for preparing the dataset, I got this error. I can't import cpu.

@szy4017
Copy link
Author

szy4017 commented Sep 8, 2021

I found one of the reasons for this error is that the compiler can't find the 'cpu.py'. In particular, because the name of package is the same as the name of project file, the compiler is confused.

@szy4017
Copy link
Author

szy4017 commented Sep 8, 2021

A simple solution is that we can copy the files in packeage enconding to project dir encoding.
The comands are as follows.

cp /home/user/.conda/envs/Pytorch-Encoding/lib/python3.6/site-packages/torch_encoding-1.2.2b20210908-py3.6-linux-x86_64.egg/encoding/cpu.py /home/user/PyTorch-Encoding/encoding/
cp /home/user/.conda/envs/Pytorch-Encoding/lib/python3.6/site-packages/torch_encoding-1.2.2b20210908-py3.6-linux-x86_64.egg/encoding/cpu.cpython-36m-x86_64-linux-gnu.so /home/user/PyTorch-Encoding/encoding/
cp /home/user/.conda/envs/Pytorch-Encoding/lib/python3.6/site-packages/torch_encoding-1.2.2b20210908-py3.6-linux-x86_64.egg/encoding/gpu.py /home/user/PyTorch-Encoding/encoding/
cp /home/user/.conda/envs/Pytorch-Encoding/lib/python3.6/site-packages/torch_encoding-1.2.2b20210908-py3.6-linux-x86_64.egg/encoding/gpu.cpython-36m-x86_64-linux-gnu.so /home/user/PyTorch-Encoding/encoding/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant