  The key ingredient to retrieving a signal from its Fourier magnitudes,
namely, to solve the phase retrieval problem, is an effective prior on the
sought signal. In this paper, we study the phase retrieval problem under the
prior that the signal lies in a semi-algebraic set. This is a very general
prior as semi-algebraic sets include linear models, sparse models, and ReLU
neural network generative models. The latter is the main motivation of this
paper, due to the remarkable success of deep generative models in a variety of
imaging tasks, including phase retrieval. We prove that almost all signals in
R^N can be determined from their Fourier magnitudes, up to a sign, if they lie
in a (generic) semi-algebraic set of dimension N/2. The same is true for all
signals if the semi-algebraic set is of dimension N/4. We also generalize these
results to the problem of signal recovery from the second moment in
multi-reference alignment models with multiplicity free representations of
compact groups. This general result is then used to derive improved sample
complexity bounds for recovering band-limited functions on the sphere from
their noisy copies, each acted upon by a random element of SO(3).
