matteo-ronchetti / torch-radon

Computational Tomography in PyTorch
https://torch-radon.readthedocs.io
GNU General Public License v3.0
219 stars 45 forks source link

NameError: name 'RaysCfg' is not defined #23

Closed zhouqp631 closed 3 years ago

zhouqp631 commented 3 years ago

Hi,

The package is installed correctly, but it is not working. There is name 'RaysCfg' is not defined error, how can i fix it?

Thanks!

  1. installation

    (dlenv) $ python auto_install.py Checking requirements Operating System: linux OK Python version: 3.6 OK PyTorch: 1.7 OK CUDA: 10.1 OK Executing: pip install --force-reinstall https://rosh-public.s3-eu-west-1.amazonaws.com/radon/cuda-10.1/torch-1.7/torch_radon-1.0.0-cp36-cp36m-linux_x86_64.whl Collecting torch-radon==1.0.0 Using cached https://rosh-public.s3-eu-west-1.amazonaws.com/radon/cuda-10.1/torch-1.7/torch_radon-1.0.0-cp36-cp36m-linux_x86_64.whl (1.0 MB) Collecting scipy Using cached scipy-1.5.4-cp36-cp36m-manylinux1_x86_64.whl (25.9 MB) ... Successfully installed Pillow-8.2.0 alpha-transform-0.0.1 astropy-4.1 cycler-0.10.0 healpy-1.14.0 kiwisolver-1.3.1 matplotlib-3.3.4 numexpr-2.7.3 numpy-1.19.5 pyfftw-0.12.0 pyparsing-2.4.7 python-dateutil-2.8.1 scipy-1.5.4 six-1.15.0 torch-radon-1.0.0 tqdm-4.60.0`

  2. when I test 'examples/fbp.py', error shows

NameError Traceback (most recent call last)

in ----> 1 **radon = Radon(image_size, angles, clip_to_circle=True)** ~/.conda/envs/dlenv/lib/python3.6/site-packages/torch_radon/__init__.py in __init__(self, resolution, angles, det_count, det_spacing, clip_to_circle) 167 det_count = resolution 168 --> 169 rays_cfg = RaysCfg(resolution, resolution, det_count, det_spacing, len(angles), clip_to_circle) 170 171 super().__init__(angles, rays_cfg) **NameError: name 'RaysCfg' is not defined**
  1. system info

    Linux version 3.10.0-862.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018

    NVIDIA-SMI 418.152.00
    Driver Version: 418.152.00
    CUDA Version: 10.1

matteo-ronchetti commented 3 years ago

Can you give me the full output of examples/fbp.py I think it should print "Importing exception"

zhouqp631 commented 3 years ago

The installation is all right, I do not know why occer Importing exception

$ python fbp.py Importing exception Importing exception Traceback (most recent call last): File "fbp.py", line 16, in radon = Radon(image_size, angles, clip_to_circle=True) File "/public/home/hpc220115/.conda/envs/dlenv/lib/python3.6/site-packages/torch_radon/init.py", line 169, in init rays_cfg = RaysCfg(resolution, resolution, det_count, det_spacing, len(angles), clip_to_circle) NameError: name 'RaysCfg' is not defined Exception ignored in: <bound method BaseRadon.del of <torch_radon.Radon object at 0x2ae8005392b0>> Traceback (most recent call last): File "/public/home/hpc220115/.conda/envs/dlenv/lib/python3.6/site-packages/torch_radon/init.py", line 140, in del self.noise_generator.free() AttributeError: 'Radon' object has no attribute 'noise_generator'

matteo-ronchetti commented 3 years ago

There is a problem in doing import torch_radon_cuda. Can you try running python and then import torch and import torch_radon_cuda?

zhouqp631 commented 3 years ago
Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 21:15:04) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import torch
 >>> import torch_radon_cuda
 >>> 
matteo-ronchetti commented 3 years ago

Try running python and then import torch and from torch_radon_cuda import RaysCfg?

zhouqp631 commented 3 years ago
>>> import torch
>>> from torch_radon_cuda import RayCfg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'RayCfg' from 'torch_radon_cuda' 
(/public/home/*/.conda/envs/py38/lib/python3.8/site-packages/torch_radon-1.0.0-py3.8-
linux-x86_64.egg/torch_radon_cuda.cpython-38-x86_64-linux-gnu.so)
matteo-ronchetti commented 3 years ago

I don't know why it is trying to import the Python 3.8 library while you are using python 3.6. Let's try to reinstall the library with pip install --force-reinstall --no-cache-dir https://rosh-public.s3-eu-west-1.amazonaws.com/radon/cuda-10.1/torch-1.7/torch_radon-1.0.0-cp36-cp36m-linux_x86_64.whl

zhouqp631 commented 3 years ago

sorry I mix up the environment. I test different python version for the installation. Now I reinstall packages with your code, and get error information like

Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 21:15:04) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> from torch_radon_cuda import RayCfg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /public/home/*/.conda/envs/dlenv/lib/python3.6/site-packages/torch_radon_cuda.cpython-36m-x86_64-linux-gnu.so)
matteo-ronchetti commented 3 years ago

The problem is that your system has an old version of the GNU C library and TorchRadon is linked against a newer version. In order to check this you can run ldd --version and you should get a version < 2.27. I thought that this problem was fixed with the changes I have made in order to solve #5 but I was wrong. I will try to find a solution to this problem in the next few days and let you know as soon as I solve it. In the meantime you can consider using TorchRadon inside a Docker container or you can compile the library from source.

zhouqp631 commented 3 years ago

Many thanks. I do get version<2.27 using ldd --version. I want to install TorchRadon in HPC, but I can not update GNU C for I do not have the authority. So, I'll try Docker container.

matteo-ronchetti commented 3 years ago

Can you please tell me the version you get using ldd --version?

zhouqp631 commented 3 years ago
  1. glibc verison
    (base) [*@gpu208 ~]$ ldd --version
    ldd (GNU libc) 2.17
  2. gcc-9.3.0 and gcc-10.1.0 are available.

By the way, could you tell me how to compile the TorchRadon with specified version of gcc and glibc?

matteo-ronchetti commented 3 years ago

TorchRadon itself doesn't need a very new version of gcc or glibc, the problem is that precompiled binaries are linked against a modern version of glibc and this creates incompatibilities with "old" distributions of Linux.

I have changed the compilation in the branch "v2" where I am working on a new version of TorchRadon it's a work in progress but you can use the functions of the previous version without any problem. You can install the new version by running:

wget -qO- https://raw.githubusercontent.com/matteo-ronchetti/torch-radon/v2/auto_install.py  | python -

Otherwise it is possible to put a new version of GLIB in your home directory and make Python use that instead of the system glib. If even the new version has problems with glib I will write a tutorial on how to do it.

zhouqp631 commented 3 years ago

I have successfully installed the new version 'v2' and it works well. Thanks for your timely reply!