当前位置:网站首页>From TF 1 X to TF 2.6 (update if you encounter it)

From TF 1 X to TF 2.6 (update if you encounter it)

2022-06-26 09:51:00 A cloud in the sky

I use it tensorflow 2.6

Generally speaking, in tf 2.x You can use tf.compat.v1.xxxxxx To replace the original tf 1.x Medium tf.xxxxxx

If you make a mistake , Say the function doesn't , In fact, you can go directly to github Of tensorflow Search for this function in the project , see tensorflow How is it used in

Here is a list of the problems encountered

tf 1.x:tf.contrib.layers.xavier_initializer

tf 2.6:tf.keras.initializers.glorot_normal

tf 1.x:tf.contrib.layers

tf 2.6:tf.keras.layers

tf 1.x:from tensorflow.contrib import tpu

tf 2.6:from tensorflow import tpu

tf 1.x:from tensorflow.contrib import data

tf 2.6:from tensorflow import data

tf 1.x:from tensorflow.contrib import metrics

tf 2.6:from tensorflow import metrics

tf 1.x: from tensorflow.contrib import cluster_resolver

tf 2.6: from tensorflow.python.distribute import cluster_resolver

tf 1.x: tf.contrib.layers.layer_norm

tf 2.6: tf.keras.layers.LayerNormalization

The two functions are implemented differently , You can't just change your name

Keras 2.2.5:from keras.optimizers import Adam

Keras 2.6.0:from keras.optimizer_v2.adam import Adam

Keras 2.2.5:from keras.utils import to_categorical

Keras 2.6.0:from keras.utils.np_utils import to_categorical

RuntimeError: When eager execution is enabled, var_list must specify a list or dict of variables to save

When eager execution When it's on ,loss It should be a Python function .
stay Tensorflow 2.0 in ,eager execution Is turned on by default .
therefore , Need to close first eager execution

import tensorflow as tf

tf.compat.v1.disable_eager_execution()
 

原网站

版权声明
本文为[A cloud in the sky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260915129121.html