Skip to content

Commit

Permalink
Exception handle and resume from interruption
Browse files Browse the repository at this point in the history
  • Loading branch information
laqieer committed Jul 28, 2024
1 parent 7a26830 commit 18649a9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions music/trans/mt3/colab/music_transcription_with_transformers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,18 @@
"#@markdown This may take a few minutes depending on the length of the audio file\n",
"#@markdown you uploaded.\n",
"\n",
"import warnings\n",
"\n",
"load_gtag()\n",
"\n",
"output_path = os.path.join('FEHRR/trans/mt3/', MODEL)\n",
"if not os.path.exists(output_path):\n",
" os.makedirs(output_path)\n",
"\n",
"for filename, audio in audios.items():\n",
" if os.path.exists(os.path.join(output_path, filename[:-4] + '.mid')):\n",
" continue\n",
"\n",
" log_event('transcribeStart', {\n",
" 'event_category': MODEL,\n",
" 'filename': filename,\n",
Expand All @@ -463,14 +468,17 @@
" # note_seq.play_sequence(est_ns, synth=note_seq.fluidsynth,\n",
" # sample_rate=SAMPLE_RATE, sf2_path=SF2_PATH)\n",
"\n",
" fig = note_seq.plot_sequence(est_ns, show_figure=False)\n",
" fig.background_fill_color = None\n",
" fig.border_fill_color = None\n",
" export_png(fig, filename=os.path.join(output_path, filename.replace('.ogg', '.png')), webdriver=webdriver)\n",
" fig.output_backend = \"svg\"\n",
" export_svg(fig, filename=os.path.join(output_path, filename.replace('.ogg', '.svg')), webdriver=webdriver)\n",
"\n",
" note_seq.sequence_proto_to_midi_file(est_ns, os.path.join(output_path, filename.replace('.ogg', '.mid')))\n"
" try:\n",
" fig = note_seq.plot_sequence(est_ns, show_figure=False)\n",
" fig.background_fill_color = None\n",
" fig.border_fill_color = None\n",
" export_png(fig, filename=os.path.join(output_path, filename[:-4] + '.png'), webdriver=webdriver)\n",
" fig.output_backend = \"svg\"\n",
" export_svg(fig, filename=os.path.join(output_path, filename[:-4] + '.svg'), webdriver=webdriver)\n",
" except Exception as e:\n",
" warnings.warn('Exception occurred in note sequence figure of ' + filename[:-4] + ': ' + str(e))\n",
"\n",
" note_seq.sequence_proto_to_midi_file(est_ns, os.path.join(output_path, filename[:-4] + '.mid'))\n"
]
},
{
Expand Down

0 comments on commit 18649a9

Please sign in to comment.