From bb8715e2c72893ccb067567dbb9ecdad78326e5a Mon Sep 17 00:00:00 2001 From: Nao Tokui Date: Thu, 19 Dec 2019 20:19:50 +0900 Subject: [PATCH] added: training with duration data --- melodyvae.js | 28 +-- melodyvae.maxpat | 443 ++++++++++++++++++++++++++++++++++++----------- src/data.js | 2 - src/vae.js | 24 +-- 4 files changed, 369 insertions(+), 128 deletions(-) diff --git a/melodyvae.js b/melodyvae.js index d10d16e..cd8e02b 100644 --- a/melodyvae.js +++ b/melodyvae.js @@ -46,7 +46,7 @@ function getNoteIndexAndTimeshift(note, tempo){ // duration const durationUnit = (60.0 / tempo) * 2.0; // the duration of half note - const duration = Math.max(0.1, Math.min(note.duration / durationUnit, 1.0)); + const duration = Math.max(0.1, Math.min(note.duration / durationUnit, 2.0)); return [index, timeshift, duration]; } @@ -110,15 +110,16 @@ function processPianoroll(midiFile){ } }); - // // /* for debug - output pianoroll */ - // if (augments.length > 0){ - // var index = utils.getRandomInt(augments.length); - // let x = augments[index]; - // for (var i=0; i< NUM_MIDI_CLASSES; i++){ - // for (var j=0; j < LOOP_DURATION; j++){ - // Max.outlet("matrix_output", j, i, Math.ceil(x[i][j])); - // } - // } + // /* for debug - output pianoroll */ + // if (durations.length > 0){ + // var index = utils.getRandomInt(durations.length); + // let x = durations[index]; + // // for (var i=0; i< NUM_MIDI_CLASSES; i++){ + // // for (var j=0; j < LOOP_DURATION; j++){ + // // // Max.outlet("matrix_output", j, i, Math.ceil(x[i][j])); + // // } + // // } + // console.log(x); // } // 2D array to tf.tensor2d @@ -154,7 +155,6 @@ Max.addHandler("midi", (filename) => { // iterate over *.mid or *.midi files // TODO: it may match *.mido *.midifile *.middleageman etc... glob(filename + '**/*.mid', {}, (err, files)=>{ - console.log(files); if (err) console.log(err); else { for (var idx in files){ @@ -199,7 +199,7 @@ async function generatePattern(z1, z2, threshold){ if (isGenerating) return; isGenerating = true; - let pattern = vae.generatePattern(z1, z2); + let [pattern, durations] = vae.generatePattern(z1, z2); Max.outlet("matrix_clear",1); // clear all // Velocity @@ -221,6 +221,7 @@ async function generatePattern(z1, z2, threshold){ for (var k=0; k< 16; k++){ // 16 = number of monophonic sequence in live.step var pitch_sequence = []; var velocity_sequence = []; + var duration_sequence = []; for (var j=0; j < LOOP_DURATION; j++){ var count = 0; @@ -229,18 +230,21 @@ async function generatePattern(z1, z2, threshold){ if (count > k) { pitch_sequence.push(i + MIN_MIDI_NOTE); velocity_sequence.push(Math.floor(pattern[i][j]*127.)); + duration_sequence.push(Math.min(Math.floor(durations[i][j]*64.), 127)); break; } } if (count <= k){ // padding if there is no note pitch_sequence.push(0); velocity_sequence.push(0); + duration_sequence.push(0); } } // output for live.step object Max.outlet("pitch_output", k+1, pitch_sequence.join(" ")); Max.outlet("velocity_output", k+1, velocity_sequence.join(" ")); + Max.outlet("duration_output", k+1, duration_sequence.join(" ")); } Max.outlet("generated", 1); diff --git a/melodyvae.maxpat b/melodyvae.maxpat index 2d203d0..024365a 100644 --- a/melodyvae.maxpat +++ b/melodyvae.maxpat @@ -4,7 +4,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -62,11 +62,11 @@ "presentation_rect" : [ 961.5, 35.467153284671525, 61.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.menu[4]", - "parameter_mmax" : 16, "parameter_shortname" : "live.menu", "parameter_enum" : [ "all tracks", "track 1", "track 2", "track 3", "track 4", "track 5", "track 6", "track 7", "track 8", "track 9", "track 10", "track 11", "track 12", "track 13", "track 14", "track 15", "track 16" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.menu[4]", + "parameter_mmax" : 16 } } @@ -143,12 +143,12 @@ "presentation_rect" : [ 449.841102361679077, 100.131386861313871, 75.75, 20.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.tab", - "parameter_mmax" : 3, "parameter_shortname" : "live.tab", "parameter_enum" : [ "0.5", "1", "2", "4" ], "parameter_type" : 2, - "parameter_unitstyle" : 0 + "parameter_unitstyle" : 0, + "parameter_longname" : "live.tab", + "parameter_mmax" : 3 } } @@ -170,11 +170,11 @@ "presentation_rect" : [ 961.5, 10.064323425292969, 44.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.text[5]", - "parameter_mmax" : 1, "parameter_shortname" : "live.text[5]", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.text[5]", + "parameter_mmax" : 1 } } @@ -202,6 +202,7 @@ "id" : "obj-43", "loopruler" : 0, "maxclass" : "live.step", + "mode" : 1, "nseq" : 16, "numinlets" : 1, "numoutlets" : 5, @@ -209,13 +210,13 @@ "parameter_enable" : 1, "patching_rect" : [ 1073.0, 528.5, 450.0, 168.0 ], "presentation" : 1, - "presentation_rect" : [ 529.591102361679077, 7.0625, 425.0, 152.128646850585938 ], + "presentation_rect" : [ 529.591102361679077, 7.0625, 425.0, 156.467606704600541 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.step", - "parameter_invisible" : 1, "parameter_shortname" : "live.step", - "parameter_type" : 3 + "parameter_type" : 3, + "parameter_longname" : "live.step", + "parameter_invisible" : 1 } } @@ -293,7 +294,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -471,13 +472,13 @@ "presentation_rect" : [ 473.091102361679077, 125.0, 28.0, 36.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "threshold", - "parameter_mmax" : 50.0, - "parameter_initial" : [ 10 ], "parameter_shortname" : "thresh", "parameter_type" : 1, "parameter_unitstyle" : 0, - "parameter_mmin" : 1.0 + "parameter_mmin" : 1.0, + "parameter_longname" : "threshold", + "parameter_mmax" : 50.0, + "parameter_initial" : [ 10 ] } } @@ -581,11 +582,11 @@ "presentation_rect" : [ 961.5, 54.467153284671525, 61.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.menu", - "parameter_mmax" : 3, "parameter_shortname" : "live.menu", "parameter_enum" : [ "All", "Pitch", "Velocity", "Duration" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.menu", + "parameter_mmax" : 3 } } @@ -678,7 +679,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -735,7 +736,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -1242,12 +1243,12 @@ "presentation_rect" : [ 257.216102361679077, 54.467153284671525, 41.0, 18.5 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.text[4]", - "parameter_invisible" : 2, - "parameter_mmax" : 1, "parameter_shortname" : "live.text", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.text[4]", + "parameter_invisible" : 2, + "parameter_mmax" : 1 } } @@ -1272,12 +1273,12 @@ "presentation_rect" : [ 211.466102361679077, 54.467153284671525, 45.0, 18.5 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.text[3]", - "parameter_invisible" : 2, - "parameter_mmax" : 1, "parameter_shortname" : "live.text", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.text[3]", + "parameter_invisible" : 2, + "parameter_mmax" : 1 } } @@ -1326,7 +1327,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -1601,7 +1602,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -2036,7 +2037,7 @@ "presentation_rect" : [ 210.216102361679077, 105.167883211678827, 93.0, 54.46076363890711 ], "setminmax" : [ 0.0, 150.0 ], "setstyle" : 1, - "size" : 100 + "size" : 5 } } @@ -2123,10 +2124,10 @@ "patching_rect" : [ 680.0, 39.5, 44.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "Y", "parameter_shortname" : "Y", "parameter_type" : 0, - "parameter_unitstyle" : 0 + "parameter_unitstyle" : 0, + "parameter_longname" : "Y" } } @@ -2146,10 +2147,10 @@ "patching_rect" : [ 554.0, 39.5, 44.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "X", "parameter_shortname" : "X", "parameter_type" : 0, - "parameter_unitstyle" : 0 + "parameter_unitstyle" : 0, + "parameter_longname" : "X" } } @@ -2170,7 +2171,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -2332,7 +2333,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -2524,11 +2525,11 @@ "presentation_rect" : [ 173.216102361679077, 125.0, 34.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.numbox[3]", - "parameter_invisible" : 2, "parameter_shortname" : "live.numbox", "parameter_type" : 0, - "parameter_unitstyle" : 1 + "parameter_unitstyle" : 1, + "parameter_longname" : "live.numbox[3]", + "parameter_invisible" : 2 } } @@ -2587,12 +2588,12 @@ "presentation_rect" : [ 163.716102361679077, 27.467153284671532, 75.75, 22.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.text[2]", - "parameter_invisible" : 2, - "parameter_mmax" : 1, "parameter_shortname" : "live.text", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.text[2]", + "parameter_invisible" : 2, + "parameter_mmax" : 1 } } @@ -2629,12 +2630,12 @@ "presentation_rect" : [ 104.75, 5.584626608521404, 43.25, 18.705746782957192 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.text[1]", - "parameter_invisible" : 2, - "parameter_mmax" : 1, "parameter_shortname" : "live.text", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.text[1]", + "parameter_invisible" : 2, + "parameter_mmax" : 1 } } @@ -2659,12 +2660,12 @@ "presentation_rect" : [ 254.716102361679077, 28.467153284671532, 50.0, 22.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.text", - "parameter_invisible" : 2, - "parameter_mmax" : 1, "parameter_shortname" : "live.text", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.text", + "parameter_invisible" : 2, + "parameter_mmax" : 1 } } @@ -2689,12 +2690,12 @@ "presentation_rect" : [ 78.75, 75.579608360346214, 44.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.numbox", - "parameter_invisible" : 2, - "parameter_mmax" : 127000000.0, "parameter_shortname" : "live.numbox", "parameter_type" : 0, - "parameter_unitstyle" : 0 + "parameter_unitstyle" : 0, + "parameter_longname" : "live.numbox", + "parameter_invisible" : 2, + "parameter_mmax" : 127000000.0 } } @@ -2740,10 +2741,10 @@ "rows" : 36, "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.grid", - "parameter_invisible" : 1, "parameter_shortname" : "live.grid", - "parameter_type" : 3 + "parameter_type" : 3, + "parameter_longname" : "live.grid", + "parameter_invisible" : 1 } } @@ -2833,13 +2834,13 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } , "classnamespace" : "box", - "rect" : [ 367.0, 489.0, 873.0, 994.0 ], + "rect" : [ 411.0, 812.0, 873.0, 994.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -2867,6 +2868,225 @@ "style" : "", "subpatcher_template" : "no_top", "boxes" : [ { + "box" : { + "id" : "obj-1", + "maxclass" : "newobj", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patcher" : { + "fileversion" : 1, + "appversion" : { + "major" : 8, + "minor" : 1, + "revision" : 1, + "architecture" : "x64", + "modernui" : 1 + } +, + "classnamespace" : "box", + "rect" : [ 523.0, 311.0, 640.0, 480.0 ], + "bglocked" : 0, + "openinpresentation" : 0, + "default_fontsize" : 12.0, + "default_fontface" : 0, + "default_fontname" : "Arial", + "gridonopen" : 1, + "gridsize" : [ 15.0, 15.0 ], + "gridsnaponopen" : 1, + "objectsnaponopen" : 1, + "statusbarvisible" : 2, + "toolbarvisible" : 1, + "lefttoolbarpinned" : 0, + "toptoolbarpinned" : 0, + "righttoolbarpinned" : 0, + "bottomtoolbarpinned" : 0, + "toolbars_unpinned_last_save" : 0, + "tallnewobj" : 0, + "boxanimatetime" : 200, + "enablehscroll" : 1, + "enablevscroll" : 1, + "devicewidth" : 0.0, + "description" : "", + "digest" : "", + "tags" : "", + "style" : "", + "subpatcher_template" : "no_top", + "boxes" : [ { + "box" : { + "id" : "obj-9", + "maxclass" : "newobj", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 86.0, 133.0, 71.0, 22.0 ], + "text" : "fromsymbol" + } + + } +, { + "box" : { + "id" : "obj-87", + "maxclass" : "newobj", + "numinlets" : 2, + "numoutlets" : 2, + "outlettype" : [ "", "" ], + "patching_rect" : [ 210.0, 157.0, 55.0, 22.0 ], + "text" : "zl.slice 1" + } + + } +, { + "box" : { + "id" : "obj-79", + "maxclass" : "newobj", + "numinlets" : 1, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 86.0, 177.0, 109.0, 22.0 ], + "text" : "prepend duration 1" + } + + } +, { + "box" : { + "id" : "obj-76", + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 210.0, 226.0, 82.0, 22.0 ], + "text" : "target_seq $1" + } + + } +, { + "box" : { + "id" : "obj-74", + "maxclass" : "number", + "numinlets" : 1, + "numoutlets" : 2, + "outlettype" : [ "", "bang" ], + "parameter_enable" : 0, + "patching_rect" : [ 210.0, 186.0, 50.0, 22.0 ] + } + + } +, { + "box" : { + "id" : "obj-61", + "maxclass" : "newobj", + "numinlets" : 2, + "numoutlets" : 2, + "outlettype" : [ "", "" ], + "patching_rect" : [ 50.0, 100.0, 55.0, 22.0 ], + "text" : "zl.slice 1" + } + + } +, { + "box" : { + "comment" : "", + "id" : "obj-4", + "index" : 1, + "maxclass" : "inlet", + "numinlets" : 0, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 50.0, 35.0, 30.0, 30.0 ] + } + + } +, { + "box" : { + "comment" : "", + "id" : "obj-7", + "index" : 1, + "maxclass" : "outlet", + "numinlets" : 1, + "numoutlets" : 0, + "patching_rect" : [ 86.0, 450.0, 30.0, 30.0 ] + } + + } + ], + "lines" : [ { + "patchline" : { + "destination" : [ "obj-61", 0 ], + "order" : 1, + "source" : [ "obj-4", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-87", 0 ], + "midpoints" : [ 59.5, 90.0, 219.5, 90.0 ], + "order" : 0, + "source" : [ "obj-4", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-9", 0 ], + "source" : [ "obj-61", 1 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-76", 0 ], + "source" : [ "obj-74", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-7", 0 ], + "midpoints" : [ 219.5, 414.5, 95.5, 414.5 ], + "source" : [ "obj-76", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-7", 0 ], + "source" : [ "obj-79", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-74", 0 ], + "source" : [ "obj-87", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-79", 0 ], + "source" : [ "obj-9", 0 ] + } + + } + ] + } +, + "patching_rect" : [ 210.5, 141.0, 62.0, 22.0 ], + "presentation_linecount" : 3, + "saved_object_attributes" : { + "description" : "", + "digest" : "", + "globalpatchername" : "", + "tags" : "" + } +, + "text" : "p duration" + } + + } +, { "box" : { "id" : "obj-9", "maxclass" : "newobj", @@ -2878,7 +3098,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -3096,7 +3316,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -3325,7 +3545,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -3419,7 +3639,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -3757,11 +3977,11 @@ "box" : { "id" : "obj-55", "maxclass" : "newobj", - "numinlets" : 4, - "numoutlets" : 4, - "outlettype" : [ "", "", "", "" ], - "patching_rect" : [ 54.0, 42.0, 245.0, 22.0 ], - "text" : "route velocity_output pitch_output generated" + "numinlets" : 5, + "numoutlets" : 5, + "outlettype" : [ "", "", "", "", "" ], + "patching_rect" : [ 54.0, 42.0, 332.0, 22.0 ], + "text" : "route velocity_output pitch_output duration_output generated" } } @@ -3772,7 +3992,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "bang" ], - "patching_rect" : [ 280.5, 167.0, 48.0, 22.0 ], + "patching_rect" : [ 288.5, 183.0, 48.0, 22.0 ], "text" : "del 300" } @@ -3784,7 +4004,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 280.5, 201.0, 75.0, 22.0 ], + "patching_rect" : [ 288.5, 217.0, 75.0, 22.0 ], "text" : "target_seq 0" } @@ -3816,6 +4036,14 @@ } ], "lines" : [ { + "patchline" : { + "destination" : [ "obj-3", 0 ], + "midpoints" : [ 220.0, 311.0, 63.5, 311.0 ], + "source" : [ "obj-1", 0 ] + } + + } +, { "patchline" : { "destination" : [ "obj-3", 0 ], "midpoints" : [ 379.5, 414.0, 63.5, 414.0 ], @@ -3847,26 +4075,32 @@ , { "patchline" : { "destination" : [ "obj-3", 0 ], - "midpoints" : [ 290.0, 417.5, 63.5, 417.5 ], + "midpoints" : [ 298.0, 417.5, 63.5, 417.5 ], "source" : [ "obj-53", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-1", 0 ], + "source" : [ "obj-55", 2 ] + } + } , { "patchline" : { "destination" : [ "obj-12", 0 ], - "midpoints" : [ 214.166666666666657, 101.0, 777.5, 101.0 ], + "midpoints" : [ 298.25, 126.0, 777.5, 126.0 ], "order" : 0, - "source" : [ "obj-55", 2 ] + "source" : [ "obj-55", 3 ] } } , { "patchline" : { "destination" : [ "obj-46", 0 ], - "midpoints" : [ 214.166666666666657, 99.0, 290.0, 99.0 ], "order" : 1, - "source" : [ "obj-55", 2 ] + "source" : [ "obj-55", 3 ] } } @@ -3963,11 +4197,11 @@ "presentation_rect" : [ 466.591102361679077, 26.515738354982254, 41.0, 15.0 ], "saved_attribute_attributes" : { "valueof" : { - "parameter_longname" : "live.menu[3]", - "parameter_mmax" : 1, "parameter_shortname" : "live.menu", "parameter_enum" : [ "val1", "val2" ], - "parameter_type" : 2 + "parameter_type" : 2, + "parameter_longname" : "live.menu[3]", + "parameter_mmax" : 1 } } @@ -4046,14 +4280,14 @@ "presentation_rect" : [ 468.591102361679077, 59.470346715328475, 37.0, 18.0 ], "saved_attribute_attributes" : { "valueof" : { + "parameter_shortname" : "shuffle", + "parameter_type" : 0, + "parameter_unitstyle" : 1, "parameter_longname" : "shuffle", "parameter_initial_enable" : 1, "parameter_invisible" : 2, "parameter_mmax" : 1.0, - "parameter_initial" : [ 0.1 ], - "parameter_shortname" : "shuffle", - "parameter_type" : 0, - "parameter_unitstyle" : 1 + "parameter_initial" : [ 0.1 ] } } @@ -4216,7 +4450,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -4418,7 +4652,6 @@ "patching_rect" : [ 270.0, 636.0, 164.0, 18.0 ], "presentation" : 1, "presentation_rect" : [ 4.0, 120.131386861313871, 142.0, 18.0 ], - "text" : "Start training...", "textcolor" : [ 0.999999284744263, 0.999974429607391, 0.999991297721863, 1.0 ], "textjustification" : 1 } @@ -4470,7 +4703,7 @@ "appversion" : { "major" : 8, "minor" : 1, - "revision" : 0, + "revision" : 1, "architecture" : "x64", "modernui" : 1 } @@ -4713,12 +4946,12 @@ "rightvalue" : 200, "saved_attribute_attributes" : { "valueof" : { + "parameter_shortname" : "pictslider", + "parameter_type" : 3, "parameter_longname" : "pictslider", "parameter_initial_enable" : 1, "parameter_invisible" : 1, - "parameter_initial" : [ -200, -200 ], - "parameter_shortname" : "pictslider", - "parameter_type" : 3 + "parameter_initial" : [ -200, -200 ] } } @@ -4831,6 +5064,8 @@ "saved_object_attributes" : { "autostart" : 1, "defer" : 0, + "node_bin_path" : "", + "npm_bin_path" : "", "watch" : 0 } , @@ -5553,25 +5788,25 @@ } ], "parameters" : { - "obj-58" : [ "live.menu[4]", "live.menu", 0 ], - "obj-65" : [ "live.numbox", "live.numbox", 0 ], - "obj-75" : [ "live.text[2]", "live.text", 0 ], "obj-112" : [ "threshold", "thresh", 0 ], - "obj-18" : [ "live.grid", "live.grid", 0 ], + "obj-35" : [ "shuffle", "shuffle", 0 ], + "obj-24" : [ "X", "X", 0 ], + "obj-68" : [ "live.text[1]", "live.text", 0 ], "obj-22" : [ "pictslider", "pictslider", 0 ], + "obj-90" : [ "live.text[5]", "live.text[5]", 0 ], + "obj-65" : [ "live.numbox", "live.numbox", 0 ], + "obj-25" : [ "live.menu[3]", "live.menu", 0 ], + "obj-18" : [ "live.grid", "live.grid", 0 ], "obj-67" : [ "live.text", "live.text", 0 ], - "obj-35" : [ "shuffle", "shuffle", 0 ], "obj-28" : [ "Y", "Y", 0 ], + "obj-83" : [ "live.numbox[3]", "live.numbox", 0 ], "obj-9" : [ "live.text[4]", "live.text", 0 ], "obj-2" : [ "live.text[3]", "live.text", 0 ], - "obj-25" : [ "live.menu[3]", "live.menu", 0 ], - "obj-68" : [ "live.text[1]", "live.text", 0 ], + "obj-58" : [ "live.menu[4]", "live.menu", 0 ], + "obj-75" : [ "live.text[2]", "live.text", 0 ], "obj-106" : [ "live.tab", "live.tab", 0 ], "obj-15" : [ "live.menu", "live.menu", 0 ], "obj-43" : [ "live.step", "live.step", 0 ], - "obj-90" : [ "live.text[5]", "live.text[5]", 0 ], - "obj-83" : [ "live.numbox[3]", "live.numbox", 0 ], - "obj-24" : [ "X", "X", 0 ], "parameterbanks" : { } diff --git a/src/data.js b/src/data.js index eacd172..7d1dadf 100755 --- a/src/data.js +++ b/src/data.js @@ -28,8 +28,6 @@ class DataHandler { // Shuffled indices for both training and test data this.trainIndices = tf.util.createShuffledIndices(this.NUM_TRAIN_ELEMENTS); this.testIndices = tf.util.createShuffledIndices(this.NUM_TEST_ELEMENTS); - - console.log(this.trainIndices); } getDataSize(){ diff --git a/src/vae.js b/src/vae.js index 8ef2be8..ed497a7 100644 --- a/src/vae.js +++ b/src/vae.js @@ -234,18 +234,18 @@ class ConditionalVAE { vaeLoss(yTrue, yPred) { return tf.tidy(() => { const [yTrueOn, yTrueDur] = yTrue; - const [yOn, yDur] = y; const [z_mean, z_log_var, y] = yPred; + const [yOn, yDur] = y; + const reconstruction_loss = this.reconstructionLoss(yTrueOn, yOn); let duration_loss = this.mseLoss(yTrueDur, yDur); duration_loss = duration_loss.mul(DUR_LOSS_COEF); const kl_loss = this.klLoss(z_mean, z_log_var); - - console.log("onset_loss", tf.mean(reconstruction_loss).dataSync()); - console.log("duration_loss", tf.mean(duration_loss).dataSync()); - console.log("kl_loss", tf.mean(kl_loss).dataSync()); + // console.log("onset_loss", tf.mean(reconstruction_loss).dataSync()); + // console.log("duration_loss", tf.mean(duration_loss).dataSync()); + // console.log("kl_loss", tf.mean(kl_loss).dataSync()); const total_loss = tf.mean(reconstruction_loss.add(duration_loss).add(kl_loss)); // averaged in the batch return total_loss; @@ -277,7 +277,7 @@ class ConditionalVAE { for (let i = 0; i < epochs; i++) { if (this.shouldStopTraining) break; - let batchInput; + let batchInput, batchInputDur; let testBatchInput; let trainLoss; let valLoss; @@ -289,7 +289,8 @@ class ConditionalVAE { epochLoss = 0; for (let j = 0; j < numBatch; j++) { batchInput = dataHandler.nextTrainBatch(batchSize).xs.reshape([batchSize, originalDim]); - trainLoss = await optimizer.minimize(() => this.vaeLoss(batchInput, this.apply(batchInput)), true); + batchInputDur = dataHandlerDuration.nextTrainBatch(batchSize).xs.reshape([batchSize, originalDim]); + trainLoss = await optimizer.minimize(() => this.vaeLoss([batchInput, batchInputDur], this.apply([batchInput, batchInputDur])), true); trainLoss = Number(trainLoss.dataSync()); epochLoss = epochLoss + trainLoss; // logMessage(`\t[Batch ${j + 1}] Training Loss: ${trainLoss}.\n`); @@ -317,9 +318,12 @@ class ConditionalVAE { } generate(zs){ - let outputs = this.decoder.apply(zs); - outputs = outputs.reshape([NUM_MIDI_CLASSES, LOOP_DURATION]); - return outputs.arraySync(); + let [outputsOn, outputsDur] = this.decoder.apply(zs); + + outputsOn = outputsOn.reshape([NUM_MIDI_CLASSES, LOOP_DURATION]); + outputsDur = outputsDur.reshape([NUM_MIDI_CLASSES, LOOP_DURATION]); + + return [outputsOn.arraySync(), outputsDur.arraySync()]; } async saveModel(path){