Fringe.Py icon indicating copy to clipboard operation
Fringe.Py copied to clipboard

InvalidArgumentError when running Phase Retrieval example

Open ritzann opened this issue 2 years ago • 0 comments

Hi Farhad,

In phase_recovery.ipynb, there seems to be a problem when running the cell where it tries to reconstruct with just a single intensity image. In particular, it displays the following error:

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
Cell In[3], line 7
      5 z = -300
      6 k = 2 * np.pi/532e-3
----> 7 rec = solver.solve(input_=h_sample, k=k, z=z)
      8 amp = np.abs(rec)
      9 phase = unwrap_phase(np.angle(rec))

File ~/miniconda3/envs/tf-venv/lib/python3.9/site-packages/fringe/solvers/AngularSpectrum.py:209, in AngularSpectrumSolver.solve(self, input_, k, z)
    205     raise ValueError("Input shape is incompatible.")
    207 field = self.backend.pad(input_, self.padding, self.pad_fill_value)
--> 209 tf = self.transfer_function(k, z)
    210 return self.backend.unpad(self.backend.ifft(tf * self.backend.fft(field, self.data_length), self.data_length), self.padding)

File ~/miniconda3/envs/tf-venv/lib/python3.9/site-packages/fringe/solvers/AngularSpectrum.py:182, in AngularSpectrumSolver.transfer_function(self, k, z)
    168 """
    169 Complex Optical Transfer Function (OTF) which here, is a low-pass filtered version of the propagator function.
    170 
   (...)
    179 :return: Complex-valued OTF tensor with the shape of the input tensor (independent of batch size).
    180 """
    181 #mask = self.band_limit_mask(k, z)
--> 182 p = self.propagator(k, z)
    183 #p_m = self.backend.where(mask > 0, p, 0)
    184 return p

File ~/miniconda3/envs/tf-venv/lib/python3.9/site-packages/fringe/solvers/AngularSpectrum.py:164, in AngularSpectrumSolver.propagator(self, k, z)
    160 k2_kt2 = k * k - self.kt2
    161 sqk2_kt2 = self.backend.sqrt(self.backend.abs(k2_kt2))
    162 cs = self.backend.where(k2_kt2 >= 0,
    163                         self.backend.complex(real=self.backend.zeros_like(self.kt2), imag=sqk2_kt2 * z),
--> 164                         self.backend.complex(real=-sqk2_kt2 * self.backend.abs(z), imag=self.backend.zeros_like(self.kt2)))
    165 return self.backend.exp(cs)

File ~/miniconda3/envs/tf-venv/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    151 except Exception as e:
    152   filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153   raise e.with_traceback(filtered_tb) from None
    154 finally:
    155   del filtered_tb

File ~/miniconda3/envs/tf-venv/lib/python3.9/site-packages/tensorflow/python/framework/ops.py:7262, in raise_from_not_ok_status(e, name)
   7260 def raise_from_not_ok_status(e, name):
   7261   e.message += (" name: " + name if name is not None else "")
-> 7262   raise core._status_to_exception(e) from None

InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a float tensor but is a int32 tensor [Op:Mul]

I hope you can take a look into this. Thanks a lot!

ritzann avatar Jun 22 '23 15:06 ritzann