VisualDL

class paddle.callbacks. VisualDL ( log_dir ) [源代码]

VisualDL 是一个visualdl( 飞桨可视化分析工具 )的回调类。该类将训练过程中的损失值和评价指标储存至日志文件中后,启动面板即可查看可视化结果。

参数:

  • log_dir (str) - 输出日志保存的路径。

代码示例

  1. import paddle
  2. import paddle.vision.transforms as T
  3. from paddle.static import InputSpec
  4. inputs = [InputSpec([-1, 1, 28, 28], 'float32', 'image')]
  5. labels = [InputSpec([None, 1], 'int64', 'label')]
  6. transform = T.Compose([
  7. T.Transpose(),
  8. T.Normalize([127.5], [127.5])
  9. ])
  10. train_dataset = paddle.vision.datasets.MNIST(mode='train', transform=transform)
  11. eval_dataset = paddle.vision.datasets.MNIST(mode='test', transform=transform)
  12. net = paddle.vision.LeNet()
  13. model = paddle.Model(net, inputs, labels)
  14. optim = paddle.optimizer.Adam(0.001, parameters=net.parameters())
  15. model.prepare(optimizer=optim,
  16. loss=paddle.nn.CrossEntropyLoss(),
  17. metrics=paddle.metric.Accuracy())
  18. ## uncomment following lines to fit model with visualdl callback function
  19. # callback = paddle.callbacks.VisualDL(log_dir='visualdl_log_dir')
  20. # model.fit(train_dataset, eval_dataset, batch_size=64, callbacks=callback)

使用本API的教程文档