import tensorflow as tf import tensorflow_hub as hub from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2 from tensorflow.keras import layers def h5_to_pb(h5_save_path): model = tf.keras.models.load_model(h5_save_path, custom_objects={'KerasLayer': hub.KerasLayer, 'Dense':tf.keras.layers.Dense}, compile=False) # model = tf.keras.models.load_model(h5_save_path, compile=False) model.summary() full_model = tf.function(lambda Input: model(Input)) # 下面这句话出了问题 # full_model = full_model.get_concrete_function(tf.TensorSpec(model.inputs[0].shape, model.inputs[0].dtype)) # 改成了这样子的,如愿生成了pb文件 full_model = full_model.get_concrete_function(tf.TensorSpec([None, 224, 224, 3], tf.float32)) # Get frozen ConcreteFunction frozen_func = convert_variables_to_constants_v2(full_model) frozen_func.graph.as_graph_def() layers = [op.name for op in frozen_func.graph.get_o