ml4astro / galaxy2galaxy

Library of models, datasets, and utilities to build generative models for astronomical images.
MIT License
27 stars 7 forks source link

"AttributeError: module 'tensorflow' has no attribute 'flags"' when uses command "g2g-datagen" #25

Open tycheng-sunny opened 4 years ago

tycheng-sunny commented 4 years ago

As title, I was applying g2g-datagen to generate cosmos data, then I got an error message:

File "/Users/ppxtc1/anaconda2/envs/g2g/lib/python3.6/site-packages/tensor2tensor/bin/t2t_datagen.py", line 58, in flags = tf.flags AttributeError: module 'tensorflow' has no attribute 'flags'

This might be due to Tensor2Tensor is not compatible with Tensorflow 2.

EiffL commented 4 years ago

Hi Sunny :-) Yes, so, the way to fix all of these issues is either 1 - Make sure you are using TF v1.5 2 - Replace the TF imports from this:

import tensorflow as tf

to this:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

as documented here: https://www.tensorflow.org/guide/migrate

If you wanted to open a Pull Request fixing this problem, that would be fantastic :-D

EiffL commented 4 years ago

@tycheng-sunny Actually, it's Tensor2Tensor itself that seems to be causing issues. What version of T2T and TF do you have installed? See this issue: https://github.com/tensorflow/tensor2tensor/issues/1771

tycheng-sunny commented 4 years ago

Yes I think you were right.

The error message shows up when I tried to pip install tensor2tensor. I installed TF v2.1. I have changed to TF v1.15, the error message is fixed.

However, there is another issue that: OSError: /tmp/t2t_datagen/COSMOS_25.2_training_sample/real_galaxy_catalog_25.2.fits not found.

EiffL commented 4 years ago

Ah yes, so the problem here is that you first need to download the GalSim COSMOS dataset. You can do it using:

$ galsim_download_cosmos -s 25.2
kstoreyf commented 3 years ago

hi! i'm also having tensorflow compatibility issues. i'm running the following in a colab notebook:

!pip install tensorflow-gpu==1.15
!pip install unagi
!pip install galaxy2galaxy
import tensorflow as tf
!mkdir hsc_anomaly_small
!mkdir hsc_tmp
!g2g-datagen --problem=img2img_hsc_anomaly_small --data-dir=hsc_anomaly_small --tmp_dir=hsc_tmp

i'm getting this error on the last line:

ImportError: This version of TensorFlow Datasets requires TensorFlow version >= 2.1.0; Detected an installation of version 1.15.0. Please upgrade TensorFlow to proceed.

i tried the solution above of changing the tensorflow import to

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

but i think this isn't the import causing the issue.

the notebook is here, feel free to play around: https://colab.research.google.com/drive/1hzaa5_ROrhXu-ZyTuDQ52-Kd-aaGhV0a?usp=sharing thanks!!