Open natefrisch01 opened 4 years ago
Maybe you Haven't installed Nightly Artifacts of TensorFlow. Nighty Artifacts is one core component in order to use TensorFlow eager Mode To install the nightly pip packages, do:
# For CPU only
pip install tf-nightly
# For GPU support
pip install -U tf-nightly-gpu
If it doesn't work, then add more detailed version by running the following in a Python shell:
import tensorflow as tf
print(tf.__version__)
print(tf.__git_version__)
For More Details, you can refer:- TensorFlow Eager Execution
@jaypatel15406 it's true for colab notebooks too, which say that you don't have to install anything. Simply from TF2.0 there is no contrib module anymore and these notebooks are outdated as far as I'm concerned. See this stack.
Can anybody help with it? How to convert them to TF2.0?
EDIT:
For now, I simply deleted the lines
import tensorflow as tf
tfe = tf.contrib.eager
# Eager Execution
#@markdown Check the box below if you want to use [Eager Execution](https://www.tensorflow.org/guide/eager)
#@markdown Eager execution provides An intuitive interface, Easier debugging, and a control flow comparable to Numpy. You can read more about it on the [Google AI Blog](https://ai.googleblog.com/2017/10/eager-execution-imperative-define-by.html)
use_tf_eager = False #@param {type:"boolean"}
# Use try/except so we can easily re-execute the whole notebook.
if use_tf_eager:
try:
tf.enable_eager_execution()
except:
pass
and repliced them with:
import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()
This will disable eager execution and remove dependence on tf.contrib from the code (I hope so, to this moment it did).
I think @mikeshwe started porting this code to TF2. I'll try to do my best to port the rest of notebooks as I go based on the first one (I committed to learning Bayesian Methods with this practical course). I'll push PRs after each notebook is ported.
Should we open another issue for communication?
Another solution is to downgrade: https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/issues/502
I've got a port that seems to work in TF2, at least for the second chapter, and only in eager mode. However, even running on 2 Tesla T4s the code takes hours to run (so far - my instances keep timing out).
I think there's something else gone wrong here.
ok so rather than add the option for graph mode I've added the @tf.function decorator to all the mcmc.sample_chain calls and the whole thing now runs in about 2 minutes.
I'll do some further cleanup (removing the evaluate calls - since just doing .numpy() on the result is about 30% faster and its less confusing), and extend out to the other examples. But should be an easy fix from here on out.
Maybe you Haven't installed Nightly Artifacts of TensorFlow. Nighty Artifacts is one core component in order to use TensorFlow eager Mode To install the nightly pip packages, do:
# For CPU only pip install tf-nightly # For GPU support pip install -U tf-nightly-gpu
If it doesn't work, then add more detailed version by running the following in a Python shell:
import tensorflow as tf print(tf.__version__) print(tf.__git_version__)
For More Details, you can refer:- TensorFlow Eager Execution
thank you
One easy way is you can pass your code written in TensorFlow 1.x to the below code to automatically upgrade it to TensorFlow 2.x.
$tf_upgrade_v2 \
--intree my_project/ \
--outtree my_project_v2/ \
--reportfile report.txt
The above code will replace all the commands which are deprecated in 2.x with the onces that are actually working in 2.x. And then you can run your code in TensorFlow 2.x.
In case if it throws an error and is unable to convert the complete code and then don't panic. Please open the "report.txt" file that is generated by the above code. In this file, you will find commands that are deprecated and their alternative commands that can be used in TensorFlow 2.x.
Taadaa, just replace the commands that are throwing errors with the new ones.
Example:
If the command in TensorFlow 1.x is:
tf.contrib
Then the same command in Tensorflow 2.x is:
tf.compat.v1.estimator
In the above example replace "tf.contrib" with "tf.compat.v1.estimator" and that should solve the problem.
tensorflow.contrib.eager is no longer in TensorFlow, but it's used in the jupyter notebooks and in google colab.