tensorflow2 有节点,但图 def 中没有节点

问题描述

我将模型保存为“已保存模型”。我正在尝试使用 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,activation='relu')(x)
x = Batchnormalization()(x)
x = Conv2D(64,activation='relu')(x)
x = Batchnormalization()(x)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Conv2D(128,activation='relu')(x)
x = Batchnormalization()(x)
x = Conv2D(128,strides=(1,1))(x)
x = Conv2D(256,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)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)