Skip to content

Commit

Permalink
fix about tensorboard (k2-fsa#516)
Browse files Browse the repository at this point in the history
* fix metricstracker

* fix style
  • Loading branch information
yaozengwei authored Aug 4, 2022
1 parent e538232 commit a4dd273
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 3 deletions.
11 changes: 11 additions & 0 deletions egs/librispeech/ASR/conformer_ctc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ def compute_loss(

info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = supervisions["num_frames"].sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - supervisions["num_frames"]) / feature.size(1))
.sum()
.item()
)

return loss, info


Expand Down
9 changes: 9 additions & 0 deletions egs/librispeech/ASR/conformer_ctc2/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,15 @@ def compute_loss(
# Note: We use reduction=sum while computing the loss.
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = feature_lens.sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - feature_lens) / feature.size(1)).sum().item()
)

return loss, info


Expand Down
11 changes: 11 additions & 0 deletions egs/librispeech/ASR/streaming_conformer_ctc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def compute_loss(

info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = supervisions["num_frames"].sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - supervisions["num_frames"]) / feature.size(1))
.sum()
.item()
)

return loss, info


Expand Down
11 changes: 11 additions & 0 deletions egs/librispeech/ASR/tdnn_lstm_ctc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ def compute_loss(
info["frames"] = supervision_segments[:, 2].sum().item()
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = supervisions["num_frames"].sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(2) - supervisions["num_frames"]) / feature.size(2))
.sum()
.item()
)

return loss, info


Expand Down
9 changes: 9 additions & 0 deletions egs/librispeech/ASR/transducer/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ def compute_loss(
# Note: We use reduction=sum while computing the loss.
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = feature_lens.sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - feature_lens) / feature.size(1)).sum().item()
)

return loss, info


Expand Down
9 changes: 9 additions & 0 deletions egs/librispeech/ASR/transducer_lstm/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ def compute_loss(
# Note: We use reduction=sum while computing the loss.
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = feature_lens.sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - feature_lens) / feature.size(1)).sum().item()
)

return loss, info


Expand Down
9 changes: 9 additions & 0 deletions egs/librispeech/ASR/transducer_stateless/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ def compute_loss(
# Note: We use reduction=sum while computing the loss.
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = feature_lens.sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - feature_lens) / feature.size(1)).sum().item()
)

return loss, info


Expand Down
9 changes: 9 additions & 0 deletions egs/librispeech/ASR/transducer_stateless2/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,15 @@ def compute_loss(
# Note: We use reduction=sum while computing the loss.
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = feature_lens.sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - feature_lens) / feature.size(1)).sum().item()
)

return loss, info


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ def compute_loss(
# Note: We use reduction=sum while computing the loss.
info["loss"] = loss.detach().cpu().item()

# `utt_duration` and `utt_pad_proportion` would be normalized by `utterances` # noqa
info["utterances"] = feature.size(0)
# averaged input duration in frames over utterances
info["utt_duration"] = feature_lens.sum().item()
# averaged padding proportion over utterances
info["utt_pad_proportion"] = (
((feature.size(1) - feature_lens) / feature.size(1)).sum().item()
)

return loss, info


Expand Down
7 changes: 4 additions & 3 deletions icefall/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,10 @@ def __str__(self) -> str:
else:
raise ValueError(f"Unexpected key: {k}")
frames = "%.2f" % self["frames"]
ans_frames += "over " + str(frames) + " frames; "
utterances = "%.2f" % self["utterances"]
ans_utterances += "over " + str(utterances) + " utterances."
ans_frames += "over " + str(frames) + " frames. "
if ans_utterances != "":
utterances = "%.2f" % self["utterances"]
ans_utterances += "over " + str(utterances) + " utterances."

return ans_frames + ans_utterances

Expand Down

0 comments on commit a4dd273

Please sign in to comment.