CERN / TIGRE

TIGRE: Tomographic Iterative GPU-based Reconstruction Toolbox
BSD 3-Clause "New" or "Revised" License
569 stars 187 forks source link

Python3 errors when trying to error #170

Closed resonance20 closed 4 years ago

resonance20 commented 4 years ago

Expected Behavior

FDK reconstruction should take place

Actual Behavior

Throws an error:

~\AppData\Roaming\Python\Python37\site-packages\pytigre-0.1.8-py3.7-win-amd64.egg\tigre\algorithms\single_pass_algorithms.py in FDK(proj, geo, angles, **kwargs)
    118     # scipy.io.savemat('Tests/Filter_data', m)
--> 119     res = Atb(proj_filt, geo, geo.angles, 'FDK')
    120     # res = 0

~\AppData\Roaming\Python\Python37\site-packages\pytigre-0.1.8-py3.7-win-amd64.egg\tigre\utilities\Atb.py in Atb(projections, geo, angles, krylov)
     23 
---> 24     return _Atb_ext(projections, geox, geox.angles, krylov,geox.mode)

~\AppData\Roaming\Python\Python37\site-packages\pytigre-0.1.8-py3.7-win-amd64.egg\tigre\Source\_Atb.pyx in _Atb._Atb_ext()

~\AppData\Roaming\Python\Python37\site-packages\pytigre-0.1.8-py3.7-win-amd64.egg\tigre\Source\_Atb.pyx in _Atb.cuda_raise_errors()

: (, TypeError('__str__ returned non-string (type list)'))

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_code(self, code_obj, result, async_)
   3346             if result is not None:
   3347                 result.error_in_exec = sys.exc_info()[1]
-> 3348             self.showtraceback(running_compiled_code=True)
   3349         else:
   3350             outflag = False

~\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\interactiveshell.py in showtraceback(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)
   2047                                             value, tb, tb_offset=tb_offset)
   2048 
-> 2049                     self._showtraceback(etype, value, stb)
   2050                     if self.call_pdb:
   2051                         # drop into debugger

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel\zmqshell.py in _showtraceback(self, etype, evalue, stb)
    544             u'traceback' : stb,
    545             u'ename' : unicode_type(etype.__name__),
--> 546             u'evalue' : py3compat.safe_unicode(evalue),
    547         }
    548 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ipython_genutils\py3compat.py in safe_unicode(e)
     63     """
     64     try:
---> 65         return unicode_type(e)
     66     except UnicodeError:
     67         pass

TypeError: __str__ returned non-string (type list)

Code to reproduce the problem (If applicable)

niter=5
cus_geom = CustomGeometry()
cus_geom.offOrigin = np.asarray(offsets, dtype = np.float32)
list_proj_data = np.stack(images, axis = 0).astype(np.float32)
angle_list = np.asarray(vectors, dtype = np.float32)

imgOSSART=tigre.algorithms.FDK(proj = list_proj_data, geo = cus_geom, angles = angle_list , filter='ram_lak', \
    verbose=True, blocksize=50)

The custom geometry is defined here:

class CustomGeometry(tigre.utilities.geometry.Geometry):

    def __init__(self):
            # VARIABLE                                          DESCRIPTION                    UNITS
            # -------------------------------------------------------------------------------------
            self.DSD = origin_det                                  # Distance Source Detector      (mm)
            self.DSO = source_origin                                     # Distance Source Origin        (mm)
            # Detector parameters
            self.nDetector = np.array((det_row, det_col))               # number of pixels              (px)
            self.dDetector = np.array((det_spac_x, det_spac_y))               # size of each pixel            (mm)
            self.sDetector = self.nDetector * self.dDetector    # total size of the detector    (mm)
            self.rotDetector =  np.array((0, 0, 0))
            # Image parameters
            self.nVoxel = np.array((500, 256, 256))             # number of voxels              (vx)
            self.sVoxel = np.array((500, 256, 256))             # total size of the image       (mm)
            self.dVoxel = self.sVoxel/self.nVoxel               # size of each voxel            (mm)
            # Offsets
            self.offOrigin = np.array((0, 0, 0))                # Offset of image from origin   (mm)
            self.offDetector = np.array((0, 0))                 # Offset of Detector            (mm)

            # Auxiliary
            self.accuracy = 0.5                                 # Accuracy of FWD proj          (vx/sample)
            # Mode
            self.mode = 'cone' 

Specifications

AnderBiguri commented 4 years ago

huh, not pretty. This looks like an error that has not been properly handled. The python 3 port has been recently done and well, perhaps not thoroughly tested, its plausible that the error throwing code is not good for python 3.... No idea really.

How did you install this? using pip as in the docs? Can you try this with python 2?

A couple of side notes:

I can not test this myself because your code is not complete, i.e. I dont have your data/values. I suggest to try to rewrite the demo without data requirements (using TIGREs phantoms and numerical values for geo).

FDK will not work well for Helical CT.

resonance20 commented 4 years ago

Yeah, I don't expect any great output with FDK. I was just experimenting with different algorithms to see if this error persisted across them. As far as I can tell, I encountered this error in OS-SART, SIRT, SART, and FDK.

Installation was performed from pip and subsequently from the source. There is no difference in the error ouptut in both cases.

I haven't yet tried with Python 2.

AnderBiguri commented 4 years ago

Im not a python expert at all, but this is what I suspect is happening:

Something in your geometry is not right. Perhaps some mismatchign sizes, perhaps some permuted matrix, perhaps some wrong datatype, that the tool should have caught, but it did not. Thus, the source (Atb) errors, but because the errors are were written for python2, there is a bug with unicode or something like that (reading the errors) that make the error throwing, well, error. This makes us not see what the real error is...

So the real solution is fixing the error throwing code to be compatible with python3, but to solve your problem there are 2 immediate things we can do

  1. Run this in python 2. Hopefully the error will help me kwon whats wrong
  2. Explicitly show what data you are using to run this. Hopefully that will make me see that perhaps some value is wrong/unexpected.

Ideally, both.

Otherwise I can't really help much!

resonance20 commented 4 years ago

Well after a lot of pain, I'm not able to install Tigre onto a Python 2 distribution. Installing from pip gives me a $CUDA_HOME error (unusual since I'm running Windows) and installation from source throws up a lot of nasty nvcc errors.

The data is a series of DICOM files in a DICOM-CT-PD format. The angles are in radians, and data is present as a single detector view at each position (defined by angular and axial locations). The actual data is a 16 bit projection, of shape [NumberOfDetectorRows, NumberOfDetectorColumns] each. The input to the algorithm is of size [NumberOfProjections, NumberOfDetectorRows, NumberOfDetectorColumns].

I'm happy to share the dataset, but as it several gigabytes, I don't think that is a practical solution either.

AnderBiguri commented 4 years ago

@resonance20 you don't need to share the dataset, as I have already mentioned, you shoudl be able to replace the input data with simulated data from TIGRE. That, plus replacing the variables by actual values will make a self-contained example that I could test.

resonance20 commented 4 years ago

Okay, after experimenting, I found a bug in my geometry. It seems to be working (albeit slowly) now. I think I will leave this up though, since the bug in the Python bindings is what needs to be addressed here.

AnderBiguri commented 4 years ago

@resonance20 agree! Let's leave this one up.

Unfortunately the python code is much slower than the MATLAB code, as its not properly polished yet.... I hope to find time for that at some point....

phernst commented 4 years ago

The error is probably related to a wrong implementation of TigreCudaCallError.__str__. Have a look at my pull request #174 :)

AnderBiguri commented 4 years ago

@resonance20 I haven't tested #174 but it sounds reasonable, so I will merge it. Give it a go and we can close this issue if its correct!