将 tensorflow 1.xx 模型加载到 tensorflow 2.xx 中

den*_*dog 3 python tensorflow

SavedModel创建了一个用 TF1 加载的 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().
Run Code Online (Sandbox Code Playgroud)

我想最好修复这个警告,或者只是压制它!

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

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

# In my Dockerfile
ENV TF_CPP_MIN_LOG_LEVEL 2
Run Code Online (Sandbox Code Playgroud)

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

jde*_*esa 5

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)
Run Code Online (Sandbox Code Playgroud)