本文介绍了将 tensorflow 1.x.x 模型加载到 tensorflow 2.x.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 SavedModel,其中 TF1 正在加载 TF2.

I have a SavedModel created with TF1 being loaded with TF2.

对于图中的每个变量,我都收到了一个警告,即:

I am getting a warning for each variable in the graph it seems, which is:

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().

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

I would like to preferably fix this warning, or just suppress it!

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

So far I have tried:

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

# In my Dockerfile
ENV TF_CPP_MIN_LOG_LEVEL 2

这个模型来自 tensorflow hub,因此我还没有构建它.

this model is from tensorflow hub, therefore I have not built it.

推荐答案

登录 TensorFlow 在最近的版本中发生了变化,并且不再使用 TF_CPP_MIN_LOG_LEVEL(请参阅问题 #26348#31870).尝试使用 tf.get_logger().setLevel('ERROR').

Logging in TensorFlow changed in more recent versions, and TF_CPP_MIN_LOG_LEVEL is not used anymore (see issues #26348 and #31870). Try with 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)

这篇关于将 tensorflow 1.x.x 模型加载到 tensorflow 2.x.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 02:36