我将模型保存为“已保存模型”。我正在尝试使用freeze graph.py冻结图形, 但它失败并出现错误(dense_1/BiasAdd 不在图形中)所以,我跟踪并打印了图形定义。
有节点def,但图def中没有节点。
node_def { name: "dense_1/BiasAdd" op: "BiasAdd" input: "dense_1/MatMul:product:0" input: "dense_1/BiasAdd/ReadVariableOp:value:0" attr { key: "T" value { type: DT_FLOAT } } attr { key: "_output_shapes" value { list { shape { dim { size: -1 } dim { size: 136 } } } } } experimental_debug_info { original_node_names: "dense_1/BiasAdd" } }
在 tensorflow 1 中,我可以找到输出节点。
node { name: "layer6/logits/BiasAdd" op: "BiasAdd" input: "layer6/logits/MatMul" input: "layer6/logits/bias/read" attr { key: "T" value { type: DT_FLOAT } } attr { key: "_output_shapes" value { list { shape { dim { size: -1 } dim { size: 136 } } } } } attr { key: "data_format" value { s: "NHWC" } } }
首先,我想知道为什么tensorflow 2 graph def中没有输出节点。
其次,我想在 tensorflow2 keras 模型中冻结图形。(我可以在 tensorflow 1.15 中做到这一点)
这是模型。
input_tensor = Input(shape=(WIDTH, HEIGHT, DEPTH)) x = Conv2D(32, 3, activation='relu')(input_tensor) x = BatchNormalization()(x) x = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(x) x = Conv2D(64, 3, activation='relu')(x) x = BatchNormalization()(x) x = Conv2D(64, 3, activation='relu')(x) x = BatchNormalization()(x) x = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(x) x = Conv2D(64, 3, activation='relu')(x) x = BatchNormalization()(x) x = Conv2D(64, 3, activation='relu')(x) x = BatchNormalization()(x) x = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(x) x = Conv2D(128, 3, activation='relu')(x) x = BatchNormalization()(x) x = Conv2D(128, 3, activation='relu')(x) x = BatchNormalization()(x) x = MaxPooling2D(pool_size=(2, 2), strides=(1, 1))(x) x = Conv2D(256, 3, activation='relu')(x) x = BatchNormalization()(x) x = Flatten()(x) x = Dense(256, activation='relu')(x) x = BatchNormalization()(x) output_tensor = Dense(LANDMARK*2)(x) model = Model(input_tensor, output_tensor)