Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions fluid/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
import paddle.v2.fluid as fluid
import paddle.v2.fluid.profiler as profiler

from visualdl import LogWriter

logwriter = LogWriter("./tmp", sync_cycle=100)
with logwriter.mode("train") as writer:
loss_scalar = writer.scalar("loss")
acc_scalar = writer.scalar("acc")

SEED = 1
DTYPE = "float32"

Expand Down Expand Up @@ -105,6 +112,7 @@ def run_benchmark(model, args):
pr = cProfile.Profile()
pr.enable()
start_time = time.time()
step = 0
# Input data
images = fluid.layers.data(name='pixel', shape=[1, 28, 28], dtype=DTYPE)
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
Expand Down Expand Up @@ -161,6 +169,11 @@ def run_benchmark(model, args):
end = time.time()
loss = np.array(outs[0])
acc = np.array(outs[1])

loss_scalar.add_record(step, loss)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loss 必须是一个 scalar,就是个数字,而非 numpy 或 list

pybind 直接会类型错误

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please throw an exception instead of terminating.

acc_scalar.add_record(step, acc)
step += 1

print("pass=%d, batch=%d, loss=%f, error=%f, elapse=%f" %
(pass_id, batch_id, loss, 1 - acc, (end - start) / 1000))

Expand Down
3 changes: 3 additions & 0 deletions fluid/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
visualdl
numpy
paddlepaddle