update/optimization_and_modeling->[update] optimzation.py and modeling.py for tensorflow 2x. #1414
+48
−44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MOTIVATION
PR to resolve AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'
optimization.py
:tf.train.Optimizer
->tf.compat.v1.train.Optimizer
due to tensorflow 2x. src: [ https://www.tensorflow.org/api_docs/python/tf/compat/v1 ]modeling.py
: (due to changes made inoptimization.py
)add
@tf.function
decorator aboveget_shape_list(...)
due to eager execution enabled by default in tensorflow 2x. src: [ https://www.tensorflow.org/guide/function ]change
tf.get_variable
->tf.compat.v1.get_variable
.change
tf.variable_score
->tf.compat.v1.variable_score
.change
tf.truncated_normal_initializer
->tf.compat.v1.truncated_normal_initializer
.change
tf.assert_less_equal
->tf.compat.v1.assert_less_equal
.change
tf.get_variable_scope
->tf.compat.v1.get_variable_scope
. src: [ https://www.tensorflow.org/api_docs/python/tf/compat/v1 ]change
tf.layers.dense
->tf.keras.layers.Dense
due to Keras 3.change
tf.contrib.layers.layer_norm
->tf.keras.layers.LayerNormalization
. src: [ https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense ] src: [ https://stackoverflow.com/a/62357941/11492382 ]CONFIGURATION
Reported-by : Майкл Шодеке
Signed-off-by: Майкл Шодеке