b-remy / gems

GEnerative Morphology for Shear
MIT License
0 stars 0 forks source link

Tf1.15/deep galaxy model #16

Open b-remy opened 2 years ago

b-remy commented 2 years ago

It turns out we can use edward2 within Tensorflow Probability (0.7.0) compatible with TensorFlow 1.15. So I was able to run the latests scripts after a few updates of the code :-)

Thanks to this, I think that there is no need to change the PPL to tfp.JointDistributionCoroutine since I am used to edward2 and everything seems compatible.

I can now shift to the deep morphological model using the same framework as before.

This is still a draft pull request, I don't really know how to merge this since there is still a lot of TF2 code in the repo... Here is the code already converted to TF 1.15 (and tfp==0.7.0), compared to the latest version of the code (https://github.com/b-remy/gems/tree/gaussiansinf , ab506ca)

Also note that it requires to install GalFlow from https://github.com/b-remy/GalFlow/tree/tf1

b-remy commented 2 years ago

For the illustration, here are some plots using the tf-1.15 version of the code:

image image

For longer chains, see https://github.com/b-remy/gems/issues/11#issuecomment-1151476123

b-remy commented 2 years ago

A simple first task to test the deep_galaxy_model is to fit the latent variables to a set of observations. This is the aim of MAP_dgm.py using edward2.

Generating observations with the COSMOS-25.2 catalog and a gaussian noise level of 0.01 we get the following fit and residuals (displayed using np.arcsinh(img/s)*s, s=1e-3):

Note that I don't fit the centroid here.

It looks like there is a very few residuals when optimizing on the latent variable :-)

However, I was not able to use tf.function with the way I imported the hub Module, because of the following error:

RuntimeError: Module must be applied in the graph it was instantiated for.

Maybe you know the right way to import the models within TensorFlow graphs @EiffL ?