Skip to content

Read time signature numerators and multirest counts with a digit CNN - #240

Open
liebharc wants to merge 6 commits into
mainfrom
issue/215
Open

liebharc wants to merge 6 commits into
mainfrom
issue/215

Conversation

@liebharc

@liebharc liebharc commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

This is an experiment for #215 : Possibly it's enough to add a simple second step which runs a digit detector (OCR, just for digits) to improve on time signatures and multi rests.

@birchb the branch is mostly auto generated and has received little testing. If you have time then it would still be interesting to hear if it improves your oboe pieces.

The transformer gives a time signature only its beat type and a multirest
no measure count. A small CNN, trained on synthetic SMuFL and font digits,
now reads the numerator of time signatures and the number above
full-measure rests. A number above such a rest turns it into a multirest
of that many measures.

- Numerators are used only if the read denominator matches the token.
- Rests are placed by barlines when their count matches the measures,
  else by attention. Rests sharing a measure by attention get no number.
- All multirests share one token (rest_2m); rest_3m..rest_10m are marked
  for removal at the next vocabulary change.
- The reader takes staff lines and bar lines from staff detection. Bar lines
  which reach from the top to the bottom line of a staff are added to it, and
  the staff is mapped into the coordinates of the transformer image.
- remove_tuplet no longer rewrites multirest counts, e.g. 5 to 4.
- The MusicXML generator writes time signatures that fit the measure
  length, e.g. 3/8 instead of 1/4, and takes the opening time from the
  first measures.

The model must be uploaded to the release as digits_v2.zip.

Claude-Session: https://claude.ai/code/session_01SGrseKTezufqJfnVwDzaYW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xavierxav

xavierxav commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

I tested #240 on the 112 Polish scores samples with the default model (566):
#240 end to end on Colab, main from an earlier run on the same scans. The run downloaded digits_v2.onnx from the onnx_checkpoints release; I didn't train
a digit model.

main #240
Native error (110 samples) 14.301% 14.302%
musicdiff error (112 samples) 22.840% 22.832%
Correct opening time signature (41 samples with a meter in the reference) 33 34
Samples with more meter changes than the reference 4 3
Measures whose length doesn't match the exported meter (of 2,768) 668 457

The overall scores barely move, but measures fit the exported meter much more often. The notes don't change, only the meter label does, so one corrected time signature fixes every measure after it. Sample 47: main exported 1/2, #240 the correct 3/4. Sample 61 goes the other way: main opened in the correct 3/4, #240 opens in 5/8 and then switches to 3/4.

Not tested: multirest counts (Polish has none) and camera photos.

AI usage: Claude and GPT agents ran and analyzed the tests; a second agent checked the figures against the saved results.


Generated by Claude Code

@liebharc

liebharc commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner Author

Thanks. https://github.com/liebharc/homr/actions/runs/45241027533 already had the same results I believe.

so one corrected time signature fixes every measure after it

I don't think it "fixes every measure", it just changes the time signature. But yes if the time signature was wrong before then they now align better and reduces the length mismatches you list.

liebharc and others added 4 commits November 25, 2026 14:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One model reads a fixed crop at the attention position and outputs the
numerator, denominator and multirest count. It's trained on rendered
Lieder and quartet staves with random time signatures and multirests,
plus DeepScores time signatures.

A measure with only rests is now a multirest candidate, as the
transformer often reads a multirest bar as several rests. The other
rests of a measure with a number are dropped.

Polish: 13.80% -> 13.81%. Sheet music photos: 4.92% -> 4.90%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #245: full-bar rests in 9/8 and 12/8 were exported four quarters long.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants