如何解决冻结 tensorflow keras 模型
这是我冻结 keras 模型的代码
import tensorflow as tf
import tensorflow.compat.v1.keras.backend as K
from tensorflow.python.framework import graph_io
graph = tf.Graph()
with graph.as_default():
sess = tf.compat.v1.Session()
K.set_session(sess)
K.set_learning_phase(0)
# load the model to graph and sess
model = tf.keras.models.load_model(os.path.join(cfg.ROOT_PATH,"models","model.h5"
),custom_objects=None)
tensor_out_name = [t.name for t in model.outputs]
# freeze the graph
graphdef = tf.compat.v1.graph_util.convert_variables_to_constants(sess,graph.as_graph_def(),tensor_out_name)
graphdef = tf.compat.v1.graph_util.remove_training_nodes(graphdef)
graph_io.write_graph(graphdef,'./',os.path.join(cfg.ROOT_PATH,"model.pb"),as_text=False)
我收到此错误:
AssertionError: Tensor("tf.concat_4/concat:0",shape=(None,None,3,6),dtype=float32) 不在图中
我不知道为什么它不能识别这个张量?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。