Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Does F1Score support MirroredStrategy for training and validation? #2629

@tabmoo

Description

@tabmoo

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
  • TensorFlow version and how it was installed (source or binary): 2.4.0, binary
  • TensorFlow-Addons version and how it was installed (source or binary): 0.14.0, binary
  • Python version: 3.8
  • Is GPU used? (yes/no): yes, DGX-2 = up to 16 V100.

Describe the bug

I'm trying to use F1Score as a metric for a semantic segmentation problem because I've read that it works by whole-batch aggregation and not by mini-batch aggregation like countless other implementations on the net do. Presumably, it also shouldn't depend on the batch size.

I've tried it in a custom loop as the validation metric for multi class problem with average=None to get separate F1 score per class. It worked reasonably well. When I tried to use it with MirroredStrategy, I got F1 > 1 for a majority class. In fact, the more gpus I use, the more value I get. Do we need to divide the result by num_replicas_in_sync?

I'll try to provide a code example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions