【问题标题】:training step and validation step different in tensorflow张量流中的训练步骤和验证步骤不同
【发布时间】:2020-05-24 07:56:33
【问题描述】:

我正在使用 tensorflow 回调在 tensorboard 上进行可视化。

tensorboard = tf.keras.callbacks.TensorBoard(
    log_dir='logs',
    histogram_freq=1,
    write_graph=True,
    write_images=True,
    update_freq='epoch',
    profile_batch=2,
    embeddings_freq=1,
    )

我正在使用简单模型并使用数据管道作为模型的输入。这里特征层包含每个特征的feature_columns:

model = tf.keras.Sequential([
    feature_layer,
    tf.keras.layers.Dense(units = 12, activation='relu', use_bias = True, kernel_initializer= 'glorot_uniform', bias_initializer = 'zeros'),
    tf.keras.layers.Dense(units = 6, activation='relu', use_bias = True, kernel_initializer= 'glorot_uniform', bias_initializer = 'zeros'),
    tf.keras.layers.Dense(units = 2, activation='softmax')
    ])

我使用 adam 作为优化器,使用稀疏分类交叉熵作为损失,使用准确度作为指标。 这是我的张量板图:

red line = train   
blue line = validation

我的问题是为什么它显示的训练步骤少于验证步骤。

【问题讨论】:

  • 嗨@Aniket Bote,你能在训练时显示epoch配置吗?

标签: python-3.x tensorflow machine-learning


【解决方案1】:

如果你查看 tf.keras.callbacks.TensorBoard 的 tensorflow 文档,在 profile_batch 的参数部分下,它是这样写的 -

profile_batch:分析批次以采样计算特征。 profile_batch 必须是非负整数或逗号分隔的正整数对字符串。一对正整数表示要分析的批次范围。默认情况下,它将分析第二批。设置 profile_batch=0 以禁用分析。必须在 TensorFlow Eager 模式下运行。

由于您设置了profile_batch=2,因此它仅显示第二批的结果。

示例 -

# profile a single batch, e.g. the 5th batch.
tensorboard_callback =
    tf.keras.callbacks.TensorBoard(log_dir='./logs', profile_batch=5)
model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])
# run the tensorboard command to view the visualizations in profile plugin.

# profile a range of batches, e.g. from 10 to 20.
tensorboard_callback =
    tf.keras.callbacks.TensorBoard(log_dir='./logs', profile_batch='10,20')
model.fit(x_train, y_train, epochs=2, callbacks=[tensorboard_callback])
# run the tensorboard command to view the visualizations in profile plugin.

设置profile_batch=0 以禁用分析。必须在 TensorFlow Eager 模式下运行。

【讨论】:

  • @Aniket Bote - 如果它回答了您的问题,请您接受并投票赞成答案。谢谢。
  • 你能看看我最新的TensorFlow问题@Tensorflow Warriors
  • @TensorflowWarriors 不过,TF 文档有点晦涩难懂。只显示第二批如何解释训练和测试之间的不一致?无论我们查看的是哪个批次,这两个步骤都应该具有相同的步数。
猜你喜欢
  • 2020-03-18
  • 1970-01-01
  • 2019-10-31
  • 1970-01-01
  • 2011-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多