bwohlberg / sporco

Sparse Optimisation Research Code
http://brendt.wohlberg.net/software/SPORCO/
BSD 3-Clause "New" or "Revised" License
258 stars 37 forks source link

Getting type casting error of "Cannot cast ufunc 'add'" while running CSC for custom dataset #34

Closed dguhanus closed 2 months ago

dguhanus commented 2 months ago

Dear Sir, I want to run Convolution Sparse Coding for CAVE for hyperspectral image analysis. I want to load 3 .png files each of them are image of a specific wavelength. Then i am concatenating them on axis 2, and then sending that to cbpdn_clr_cd.py for multi-channel CSC. I am getting an error from function ustep: _UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('uint16') with casting rule 'samekind'

If I do the type casting by adding integer in the ustep function, self.U += int(self.rsdl_r(self.AX, self.Y)) then I am getting File ~/anaconda3/envs/env_sporco/lib/python3.10/site-packages/sporco-0.2.2a2-py3.10.egg/sporco/admm/admm.py:204 in new instance = super(ADMM, cls).new(cls)

TypeError: super(type, obj): obj must be an instance or subtype of type

Please resolve this issue. I have attached the screenshot of the errors. Custom_Dataset After_Int_Conversion

bwohlberg commented 2 months ago

What's the dtype of your stacked image img? My immediate guess is that it's uint16, whereas it should be float32 or float64.

dguhanus commented 2 months ago

Dear Sir, Thank you for your reply. Yes your are correct, my data is in uint32. One work around is I should do the (max, min) scaling. But now I am able to solve this problem by 1. img1 = util.ExampleImages().image('cloth_ms20.png', scaled=True, idxexp=np.s[160:416,60:316]) img2 = util.ExampleImages().image('cloth_ms21.png', scaled=True, idxexp=np.s[160:416,60:316]) img3 = util.ExampleImages().image('cloth_ms22.png', scaled=True, idxexp=np.s[160:416,60:316]) img = np.stack((img1, img2, img3), axis=2)

  1. putting the images into the desired 'data' path.
  2. issuing the build command again.
bwohlberg commented 2 months ago

Closing as resolved.