简体   繁体   English

将 tensorflow 1.xx model 装入 tensorflow 2.xx

[英]Loading tensorflow 1.x.x model into tensorflow 2.x.x

I have a SavedModel created with TF1 being loaded with TF2.我有一个用 TF1 创建的SavedModel被 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

EDIT: this model is from tensorflow hub, therefore I have not built it.编辑:这个 model 来自 tensorflow 集线器,因此我没有构建它。

Logging in TensorFlow changed in more recent versions, and TF_CPP_MIN_LOG_LEVEL is not used anymore (see issues #26348 and #31870 ).登录 TensorFlow 在更新的版本中发生了变化,并且不再使用TF_CPP_MIN_LOG_LEVEL (参见问题#26348#31870 )。 Try with tf.get_logger().setLevel('ERROR') .尝试使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM