当训练tensorflow联合学习模型时,为什么我会看到本地时期的输出?

发布于 2025-02-08 05:33:42 字数 1966 浏览 3 评论 0原文

我正在培训一种张量子流联合学习模型。我看不到时期的输出。详细信息如下:

split = 4
NUM_ROUNDS = 5
NUM_EPOCHS = 10
BATCH_SIZE = 2
PREFETCH_BUFFER = 5

for round_num in range(1, NUM_ROUNDS+1):
    state, tff_metrics = iterative_process.next(state, federated_train_data) 
    print('round {:2d}, metrics{}'.format(round_num,tff_metrics['train'].items()))
    
    eval_model = create_keras_model()
    eval_model.compile(optimizer=optimizers.Adam(learning_rate=client_lr),
                       loss=losses.BinaryCrossentropy(),
                       metrics=[tf.keras.metrics.Accuracy()])
    
    #tff.learning.assign_weights_to_keras_model(eval_model, state.model)
    state.model.assign_weights_to(eval_model)
    
    ev_result = eval_model.evaluate(x_val, y_val, verbose=2)
    train_metrics = tff_metrics['train']
      for name, value in tff_metrics['train'].items():
            tf.summary.scalar(name,value, step=round_num)
    
    tff_val_acc.append(ev_result[1])
    tff_val_loss.append(ev_result[0])

我的输出外观如下:


    round  1, metrics=odict_items([('accuracy', 0.0), ('loss', 1.2104079)])
    1/1 - 1s - loss: 0.7230 - accuracy: 0.0000e+00 - 1s/epoch - 1s/step
    round  2, metrics=odict_items([('accuracy', 0.0007142857), ('loss', 1.2233553)])
    1/1 - 1s - loss: 0.6764 - accuracy: 0.0000e+00  - 646ms/epoch - 646ms/step
    round  3, metrics=odict_items([('accuracy', 0.0),  ('loss', 1.1939998)])
    1/1 - 1s - loss: 0.6831 - accuracy: 0.0000e+00  - 635ms/epoch - 635ms/step
    round  4, metrics=odict_items([('accuracy', 0.0), ('loss', 1.2829995)])
    1/1 - 1s - loss: 0.6830 - accuracy: 0.0000e+00  - 641ms/epoch - 641ms/step
    round  5, metrics=odict_items([('accuracy', 0.0),  ('loss', 1.2051892)])
    1/1 - 1s - loss: 0.7135 - accuracy: 0.0000e+00 - 621ms/epoch - 621ms/step

每回合后,全局模型的这些值是否吗?如何绘制曲线以确保100个时期的全局模型的验证准确性(10轮,每轮10个局部时期)? (不在张板中)

I am training a tensorflow federated learning model. I cannot see the output of epochs. Details are as follows:

split = 4
NUM_ROUNDS = 5
NUM_EPOCHS = 10
BATCH_SIZE = 2
PREFETCH_BUFFER = 5

for round_num in range(1, NUM_ROUNDS+1):
    state, tff_metrics = iterative_process.next(state, federated_train_data) 
    print('round {:2d}, metrics{}'.format(round_num,tff_metrics['train'].items()))
    
    eval_model = create_keras_model()
    eval_model.compile(optimizer=optimizers.Adam(learning_rate=client_lr),
                       loss=losses.BinaryCrossentropy(),
                       metrics=[tf.keras.metrics.Accuracy()])
    
    #tff.learning.assign_weights_to_keras_model(eval_model, state.model)
    state.model.assign_weights_to(eval_model)
    
    ev_result = eval_model.evaluate(x_val, y_val, verbose=2)
    train_metrics = tff_metrics['train']
      for name, value in tff_metrics['train'].items():
            tf.summary.scalar(name,value, step=round_num)
    
    tff_val_acc.append(ev_result[1])
    tff_val_loss.append(ev_result[0])

And my output looks as follows:


    round  1, metrics=odict_items([('accuracy', 0.0), ('loss', 1.2104079)])
    1/1 - 1s - loss: 0.7230 - accuracy: 0.0000e+00 - 1s/epoch - 1s/step
    round  2, metrics=odict_items([('accuracy', 0.0007142857), ('loss', 1.2233553)])
    1/1 - 1s - loss: 0.6764 - accuracy: 0.0000e+00  - 646ms/epoch - 646ms/step
    round  3, metrics=odict_items([('accuracy', 0.0),  ('loss', 1.1939998)])
    1/1 - 1s - loss: 0.6831 - accuracy: 0.0000e+00  - 635ms/epoch - 635ms/step
    round  4, metrics=odict_items([('accuracy', 0.0), ('loss', 1.2829995)])
    1/1 - 1s - loss: 0.6830 - accuracy: 0.0000e+00  - 641ms/epoch - 641ms/step
    round  5, metrics=odict_items([('accuracy', 0.0),  ('loss', 1.2051892)])
    1/1 - 1s - loss: 0.7135 - accuracy: 0.0000e+00 - 621ms/epoch - 621ms/step

Are these values for global model after each round? How can I plot the curves for validation accuracy of the global model for the 100 epochs (10 rounds, 10 local epochs per round)? (Not in tensorboard)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风追烟花雨 2025-02-15 05:33:42

当训练tensorflow联合学习模型时,为什么我看不到本地时期的输出?

通常,在联合学习中,客户端执行的是服务器看不到的本​​地计算。在这种情况下,服务器(或美国建模者)仅查看本地培训的结果(而不是单个时期)。

每回合之后,全局模型的这些值是否?

是的,日志记录是陈述是每一轮后全球模型的训练和验证指标的组合。请注意,联邦学习中的培训指标具有微妙的特殊性。

round  1, metrics=odict_items([('accuracy', 0.0), ('loss', 1.2104079)])

这些行是培训指标,并且由代码生成:

print('round {:2d}, metrics{}'.format(round_num,tff_metrics['train'].items()))

验证指标是由Keras打印的,这些记录语句:

 1/1 - 1s - loss: 0.7230 - accuracy: 0.0000e+00 - 1s/epoch - 1s/step

正在由此行打印:

ev_result = eval_model.evaluate(x_val, y_val, verbose=2)

如何绘制曲线以获得100个时期的全局模型的验证精度(10发,每回合10个本地时期)?

tff_val_acctff_val_loss列表应具有验证度量值,按圆数索引。使用诸如matplotlib之类的库( https://matplotlib.org/ )绘制这些曲线的选项?

Why can't I see the local epochs output when training tensorflow federated learning model?

Generally in federated learning the client is performing local computation not visible to the server. In this case, the server (or us modelers) only see the the result of that local training (not the individual epochs).

Are these values for global model after each round?

Yes, the logging is statements are a mix of both training and validation metrics of the global model after each round. Note that the training metrics in federated learning have a subtle peculiarity.

round  1, metrics=odict_items([('accuracy', 0.0), ('loss', 1.2104079)])

these lines are the training metrics, and are being produced by the code:

print('round {:2d}, metrics{}'.format(round_num,tff_metrics['train'].items()))

The validation metrics are being printed by Keras, these logging statements:

 1/1 - 1s - loss: 0.7230 - accuracy: 0.0000e+00 - 1s/epoch - 1s/step

are being printed by this line:

ev_result = eval_model.evaluate(x_val, y_val, verbose=2)

How can I plot the curves for validation accuracy of the global model for the 100 epochs (10 rounds, 10 local epochs per round)?

The tff_val_acc and tff_val_loss lists should have the validation metric values, indexed by round number. Using a library such as matplotlib (https://matplotlib.org/) could be an option for plotting these curves?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文