Why switching to TF 2:
- TensorFlow 1 will be finally phased out, although might take many years as there are already too many people using 1.x
- TensorFlow 2 Python is more similar to TensorFlow in C++
- TensorFlow 2 makes tensor maths is just like numberic maths with default and only eager mode.
What to change in TF 1 code:
- Bear in mind that there is only eager execution mode, no more session
- Replace session graph with @tf.function annotation, or just call tf.function to make graph
- No more tf.placeholder and Session.run or feed_dict, so just use tf.convert_to_tensor to convert regular numeric data to tensors before calling TensorFlow ops.
- tf.random_uniform is now tf.random.uniform
- Optimisers in tf.train are all now in tf.keras.optimizers, and no more GD (tf.train.GradientDescentOptimizer), use SGD (tf.keras.optimizers.SGD) instead.
- No more magical Someoptimiser.minimize, use these together:
- tf.GradientTape
- tf.GradientTape.gradient
- Someoptimiser.apply_gradients
- More to look in too...
Bottom line: TF 2 Python is good, more like maths, more similar to C/C++.
No comments:
Post a Comment