-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Describe the bug:
Calling Image.backproject several times on the same input signal does not lead to the same output.
To Reproduce:
#####################
# loading libraries #
#####################
import numpy as np
import aspire
from aspire.image import Image
from aspire.utils import Rotation
from aspire.volume import Volume
##################################################################
# compute yref as a set of n_img random images with size LxL and #
# back-project it #
##################################################################
n_img,L = 100,32
yref = aspire.image.Image(np.array(np.random.rand(n_img,L,L),dtype='float32'))
rots = Rotation.generate_random_rotations(n=n_img, seed=31415)
vref = yref.backproject(rots.matrices)
#####################################################################
# repeat the back-projection of yref several times and compare each #
# output back-projected volume to vref --> the diffrence should be #
# strictly zero (not satisfied here) #
#####################################################################
Nsimu = 1000
maxabserr = -np.inf
for id in range(Nsimu):
v = yref.backproject(rots.matrices)
abserr = np.max(np.abs(v.asnumpy()[0]-vref.asnumpy()[0]))
maxabserr = np.max([abserr,maxabserr])
print("simulation %d/%d : absolute error = %.3e, max. absolute error = %.3e" % (id+1,Nsimu,abserr,maxabserr))Expected behavior:
The absolute error between v and vref should be exactly zero at each simulation run. On my laptop, I end up with small (but nonzero) errors roughly equal to
Environment:
- OS: Ubuntu 22.04
- Python: 3.10.12
- ASPIRE Version: 0.12.1 dev
- CPU Type: Intel® Core™ i7-7920HQ CPU @ 3.10GHz × 8
- GPU Extensions: yes
Additional context:
I applied the same test to Volume.project leading to a perfectly repeatable behavior for this operator (see script below)
############################################################
# same experiment with the volume projection operator (OK) #
############################################################
_vref = aspire.volume.Volume(np.array(np.random.rand(L,L,L),dtype='float32'))
_yref = _vref.project(rots)
Nsimu = 1000
maxabserr = -np.inf
for id in range(Nsimu):
_y = _vref.project(rots)
abserr = np.max(np.abs(_y.asnumpy()-_yref.asnumpy()))
maxabserr = np.max([abserr,maxabserr])
print("simulation %d/%d : absolute error = %.3e, max. absolute error = %.3e" % (id+1,Nsimu,abserr,maxabserr))At first sight, the non-repeatability issue with Image.backproject does not seem to be related to potential CPU parallelization (I observed the same non-repeatable behavior when working with only one CPU). Is there any source of randomness occurring during the Image.backproject operation?