我正在使用flask和bootstrap来编写涉及张量流的网站。 目前,用户将代码输入表单,然后在计算完所有数据后,烧瓶和html代码加载页面;为表单页面造成巨大的缓冲时间。所以,我希望表加载一次 - 空 - 然后在用户点击表(或在设定的时间或新数据之后)使用表中的新计算数据时重新加载。
以下是所有相关的烧瓶代码:(以下代码从multiperceptron页面获取数字并使用这些数字运行张量流神经网络,然后将目前看到的图像数量和训练精度数字添加到a字典)
@app.route('/MultiPerceptron')
def MultiPerceptron():
return render_template("MultiPerceptron.html")
@app.route('/MultiPerceptronForm', methods=["POST"])
def MultiPerceptronForm():
#setting up of the tensor flow computational graph...
#the tensor flow session which creates the data that I will add to the data table
MultiPerceptResult=dict()
# Launch the graph
with tf.Session() as sess:
sess.run(init)
# Training cycle
for epoch in range(training_epochs):
avg_cost = 0.
total_batch = int(mnist.train.num_examples/batch_size)
images_seen_per_epoch = total_batch * batch_size
# Loop over all batches
for i in range(total_batch):
batch_x, batch_y = mnist.train.next_batch(batch_size)
# Run optimization op (backprop) and cost op (to get loss value)
_, c = sess.run([optimizer, cost], feed_dict={x: batch_x,
y: batch_y})
# Compute average loss
avg_cost += c / total_batch
# Display logs per epoch step
if epoch % display_step == 0:
images_seen = epoch * images_seen_per_epoch
print("Epoch:", '%04d' % (epoch+1), "cost=", \
"{:.9f}".format(avg_cost))
# Test model
correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
# Calculate accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print("Accuracy:", accuracy.eval({x: mnist.test.images, y: mnist.test.labels}))
#adding the new data to the dictionary****
MultiPerceptResult[images_seen] = accuracy.eval({x: mnist.test.images, y: mnist.test.labels})
return render_template('MultiPerceptronForm.html', MultiPerceptResult=MultiPerceptResult)
以下是所有相关的html代码:(以下的html代码正在使用烧瓶代码生成的字典,并通过它迭代创建一个包含所有数据的表格)
<table class="table table-hover">
<thead>
<tr>
<th>Images Seen</th>
<th>Training Accuracy</th>
</tr>
</thead>
<tbody>
{% for key, value in MultiPerceptResult.items() %}
<tr>
<th> {{ key }} </th>
<td> {{ value }} </td>
</tr>
{% endfor %}
</tbody>
</table>