【问题标题】:How can I visualize the estimator Trained model in tensorflow?如何在 tensorflow 中可视化估计器训练模型?
【发布时间】:2018-08-21 10:36:22
【问题描述】:

我创建了一个具有 3 个隐藏层的模型,并使用特定的数据集对其进行了训练。

我如何可视化模型,以及每次迭代的神经元连接和权重。

这里是python代码的sn-p:

#<ALL IMPORT STATEMENTS>
MODEL_DIR = <model_name>

def make_estimator(model_dir):
 config = run_config.RunConfig(model_dir=model_dir)
 feat_cols = [tf.feature_column.numeric_column("x", shape=<number_of_feat_cols>)]
 return estimator.DNNClassifier(config=config, hidden_units=[<>,<>,<>],feature_columns=feat_cols,n_classes=2,optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.001))

data = pd.read_csv(<csv_file>)

feat_data = data.drop('Type',axis=1)
feat_data_matrix = feat_data.as_matrix()

labels = data['Type']
labels_matrix = labels.as_matrix()

deep_model = make_estimator(MODEL_DIR)
input_fn = estimator.inputs.numpy_input_fn(x={'x':feat_data_matrix}, y=labels_matrix, shuffle=True, batch_size=10, num_epochs=1000)
tr_steps = <step_size>
deep_model.train(input_fn=input_fn,steps=tr_steps)
print ("Training Done")

在上面的代码中,我没有创建任何 tensorflow 会话,没有它我在哪里可以实现用于可视化模型的 TensorBoard API?

【问题讨论】:

    标签: python tensorflow machine-learning deep-learning tensorboard


    【解决方案1】:

    通过使用Python API,只需调用方法tf.summary.FileWriter

    然后如果将 SummaryWriter 写入的文件加载到 TensorBoard 中,就会显示图形。

    你必须像这样加载图表:

    # Launch the graph.
    current_session = tf.Session()
    current_session.run(init)
    
    # Create a summary writer, add the 'graph' to the event file.
    writer = tf.summary.FileWriter(<some-directory>, current_session.graph)
    

    here.

    【讨论】:

    • AttributeError: module 'tensorflow.python.training.training' has no attribute 'SummaryWriter' 得到这个错误
    • 试试这个:tf.summary.FileWriter
    • 这次我得到了:TypeError: add_graph() missing 2 required positional arguments: 'self' and 'graph'
    • 我得到一个只包含初始化函数的图而不是模型的图:(
    • 尝试将 MODEL_DIR 属性传递给您的模型:类似于 model_dir=FLAGS.log_dir... 也许这也可以帮助您:stackoverflow.com/questions/33663081/…
    猜你喜欢
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多