ProgBarLogger

class paddle.callbacks.ProgBarLogger ( log_freq=1, verbose=2 )

ProgBarLogger 是一个日志回调类。

参数:

  • log_freq (int,可选) - 损失值和指标打印的频率。默认值:1。

  • verbose (int,可选) - 打印信息的模式。设置为0时,不打印信息; 设置为1时,使用进度条的形式打印信息;设置为2时,使用行的形式打印信息。 设置为3时,会在2的基础上打印详细的计时信息,比如 average_reader_cost。 默认值:2。

代码示例

  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. lenet = paddle.vision.LeNet()
  12. model = paddle.Model(lenet,
  13. inputs, labels)
  14. optim = paddle.optimizer.Adam(0.001, parameters=lenet.parameters())
  15. model.prepare(optimizer=optim,
  16. loss=paddle.nn.CrossEntropyLoss(),
  17. metrics=paddle.metric.Accuracy())
  18. callback = paddle.callbacks.ProgBarLogger(log_freq=10)
  19. model.fit(train_dataset, batch_size=64, callbacks=callback)
  20. import paddle
  21. import paddle.vision.transforms as T
  22. from paddle.vision.datasets import MNIST
  23. from paddle.static import InputSpec
  24. inputs = [InputSpec([-1, 1, 28, 28], 'float32', 'image')]
  25. labels = [InputSpec([None, 1], 'int64', 'label')]
  26. transform = T.Compose([
  27. T.Transpose(),
  28. T.Normalize([127.5], [127.5])
  29. ])
  30. train_dataset = MNIST(mode='train', transform=transform)
  31. lenet = paddle.vision.LeNet()
  32. model = paddle.Model(lenet,
  33. inputs, labels)
  34. optim = paddle.optimizer.Adam(0.001, parameters=lenet.parameters())
  35. model.prepare(optimizer=optim,
  36. loss=paddle.nn.CrossEntropyLoss(),
  37. metrics=paddle.metric.Accuracy())
  38. callback = paddle.callbacks.ProgBarLogger(log_freq=10)
  39. model.fit(train_dataset, batch_size=64, callbacks=callback)