小编stu*_*art的帖子

使用Flask将JSON数据从服务器传递到客户端

我对Flask完全不熟悉,并试图弄清楚如何使用d3js强制布局显示networkx图数据.这是相关的Python代码:

@app.route("/")
def index():
    """
    When you request the root path, you'll get the index.html template.

    """
    return flask.render_template("index.html")


@app.route("/thread")
def get_graph_data(thread_id: int=3532967):
    """
    returns json of a network graph for the specified thread
    :param thread_id:
    :return:
    """
    pqdict, userdict = graphs.get_post_quote_dict(thread_id)
    G = graphs.create_graph(pqdict)
    s = graphs.graph_to_node_link(G, remove_singlets=True) # returns dict
    return flask.jsonify(s)
Run Code Online (Sandbox Code Playgroud)

这是index.html文件:

<!DOCTYPE html>
<html>
<head>
    <title>Index thing</title>
    <script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
    <link type="text/css" rel="stylesheet" href="templates/graph.css"/>
</head>
<body>
<div id="chart"></div>
<script>
    var w = 1500,
        h = 1500, …
Run Code Online (Sandbox Code Playgroud)

python json flask d3.js

4
推荐指数
1
解决办法
2638
查看次数

使用自定义Estimator的Tensorflow指标

我有一个卷积神经网络,我最近重构使用Tensorflow的Estimator API,很大程度上遵循本教程.但是,在训练期间,我添加到EstimatorSpec的度量标准没有显示在Tensorboard上,并且似乎没有在tfdbg中进行评估,尽管名称范围和度量标准存在于写入Tensorboard的图表中.

相关位model_fn如下:

 ...

 predictions = tf.placeholder(tf.float32, [num_classes], name="predictions")

 ...

 with tf.name_scope("metrics"):
    predictions_rounded = tf.round(predictions)
    accuracy = tf.metrics.accuracy(input_y, predictions_rounded, name='accuracy')
    precision = tf.metrics.precision(input_y, predictions_rounded, name='precision')
    recall = tf.metrics.recall(input_y, predictions_rounded, name='recall')

if mode == tf.estimator.ModeKeys.PREDICT:
    spec = tf.estimator.EstimatorSpec(mode=mode,
                                      predictions=predictions)
elif mode == tf.estimator.ModeKeys.TRAIN:

    ...

    # if we're doing softmax vs sigmoid, we have different metrics
    if cross_entropy == CrossEntropyType.SOFTMAX:
        metrics = {
            'accuracy': accuracy,
            'precision': precision,
            'recall': recall
        }
    elif cross_entropy == CrossEntropyType.SIGMOID:
        metrics = {
            'precision': …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

3
推荐指数
1
解决办法
1594
查看次数

标签 统计

python ×2

d3.js ×1

flask ×1

json ×1

tensorflow ×1