从tf 1.x到tf 2.6(遇到的就过来更新更新)

我用的是tensorflow 2.6

一般来说在tf 2.x中都可以使用tf.compat.v1.xxxxxx来替代原来tf 1.x中的tf.xxxxxx

如果报错,说函数没有,其实可以直接去github的tensorflow项目里搜索这个函数,看tensorflow里是怎么用的

这里列一列遇到的

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

这两个函数实现不同,不能只是换个名字

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

当eager execution开启的时候,loss应该是一个Python函数。
在Tensorflow 2.0 中,eager execution 是默认开启的。
所以,需要先关闭eager execution

import tensorflow as tf

tf.compat.v1.disable_eager_execution()
 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值