python - 将 tensorflow 1.x.x 模型加载到 tensorflow 2.x.x

标签 python tensorflow

我有一个使用 TF1 创建的 SavedModel 正在加载 TF2。

我收到了图中每个变量的警告,它是:

WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'Encoder_en/hidden_layers/tanh_layer_0/bias:0' shape=(512,) dtype=float32_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().

我想优先修复这个警告,或者只是抑制它!

到目前为止我已经尝试过:

# In my python app
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

# In my Dockerfile
ENV TF_CPP_MIN_LOG_LEVEL 2

编辑:这个模型来自 tensorflow hub,因此我没有构建它。

最佳答案

TensorFlow 中的登录在较新的版本中发生了变化,TF_CPP_MIN_LOG_LEVEL 不再使用(参见问题 #26348#31870)。尝试使用 tf.get_logger().setLevel('ERROR')

import tensorflow as tf
tf.get_logger().warning('test')
# WARNING:tensorflow:test
tf.get_logger().setLevel('ERROR')
tf.get_logger().warning('test')
# (silence)

关于python - 将 tensorflow 1.x.x 模型加载到 tensorflow 2.x.x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58626275/

相关文章:

python - json.decoder.JSONDecodeError : Expecting value: line 1 column 2 (char 1)

python - 适用于 Python 的 Amazon SQS 的替代方案

python - Tensorflow AdamOptimizer 与梯度下降

TensorFlow:有没有办法将 None 类型的列表转换为 Tensor?

python - 我可以从量化的 Tensorflow 模型中得到什么结果?

python - Keras LSTM 多输入多输出

python - 如何旋转 pandas 数据框?

python - python 中的多个 return 语句问题

python - 如何在 CMake 中设置构建时间的环境变量?

python - 在 tensorflow 中与许多输入数据文件很好地混合