Tutorial not working in Colab
Hi. I've tried running the TF-GAN Tutorial in Colab, and it's not working.
Few errors (there are more...):
SyntaxError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/pyct/parser.py in _attempt_to_parse_lambda_source(source, original_source, future_features, try_fallback)
157 try:
--> 158 return parse(source, preamble_len=len(future_features)), source
159
30 frames
SyntaxError: invalid syntax (<unknown>, line 1)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
ValueError: expected exactly one node node, found []
During handling of the above exception, another exception occurred:
UnsupportedLanguageElementError Traceback (most recent call last)
UnsupportedLanguageElementError: could not parse the source code:
.map(lambda _: tf.random_normal([bs, nd])))
This error may be avoided by creating the lambda in a standalone statement.
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-2-b8c4c89fd469> in <lambda>(_)
12
13 noise_ds = (tf.data.Dataset.from_tensors(0).repeat()
---> 14 .map(lambda _: tf.random_normal([bs, nd])))
15
16 if just_noise:
AttributeError: module 'tensorflow' has no attribute 'random_normal'
I run from this URL: https://colab.research.google.com/github/tensorflow/gan/blob/master/tensorflow_gan/examples/colab_notebooks/tfgan_tutorial.ipynb#scrollTo=zEhgLuGo8OGc Modified runtime to GPU, and started running the cells.
I think the method should be tf.random.normal instead of tf.random_normal.
I'll open a pull request.
Sorry if I'm mistaken, but I believe both colab tutorials are written to use TensorFlow 1.x, and will not run with 2.x (which will be the default on colab). Notice both have tf.logging calls early on, which is removed in TensorFlow 2.x. I believe random_normal was the method name in 1.x also.
For a temporary fix, you can add the following lines to the start of the first code cell to get the colab to run.
!pip install tensorflow==1.15.0
!pip install tensorflow-probability==0.7.0
Another alternative is to set tensorflow in compatibility mode adding tf = tf.compat.v1 after importing tf.
Notice that the tutorial imports tensorflow several times, so you must add that line after each import, or yet better, remove those unnecessary imports that overwrite the tf variable.