【问题标题】:Tensorflow Estimator API :How to get weights of each node of a trained model using estimator api of tensorflowTensorflow Estimator API:如何使用 tensorflow 的 estimator api 获取训练模型的每个节点的权重
【发布时间】:2018-03-15 18:06:31
【问题描述】:

我想获得 DNNClassifier 中每一层的每个节点的权重,使用 tensorflow 的估计器 API 进行训练。我发现可以在 keras 中获取每个节点的权重。估计器API可以吗?感谢您的帮助。

input_func = tf.estimator.inputs.pandas_input_fn(x=X_train,y=y_train,batch_size=10,num_epochs=1000,shuffle=True)

dnn_model = tf.estimator.DNNClassifier(hidden_units=[10,10,10],feature_columns=feat_cols,n_classes=2

model.train(input_fn,steps=6000)

我已经使用上面的代码来训练模型。我想进一步提取隐藏层每个节点的权重。

【问题讨论】:

    标签: python-3.x tensorflow deep-learning jupyter-notebook tensorflow-estimator


    【解决方案1】:

    是的,应该可以这样做。 您可以使用以下方法提取可训练变量名称:

    train_var_names = [var.name for var in tf.trainable_variables()]
    

    这些通常命名为'layer-0/kernel''layer-0/bias'。然后,您可以通过您的估算器(我假设您的问题中将其命名为dnn_model)访问它们的值(在训练您的网络之后)。举个例子:

    weights_0 = dnn_model.get_variable_value(train_var_names[0])
    

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      相关资源
      最近更新 更多