├── .gitignore ├── .DS_Store ├── Pop_Music_Midi ├── Roar - Verse.midi ├── Clocks - Intro.midi ├── Clocks - Verse.midi ├── Fix You - Verse.midi ├── Pompeii - Intro.midi ├── Pompeii - Verse.midi ├── Roar - Chorus.midi ├── Summer - Chorus.midi ├── Timber - Chorus.midi ├── Timber - Verse.midi ├── Toxic - Chorus.midi ├── Toxic - Verse.midi ├── Die Young - Verse.midi ├── Fix You - Chorus.midi ├── Let's Go - Verse.midi ├── Piano Man - Verse.midi ├── Pompeii - Bridge.midi ├── Pompeii - Chorus.midi ├── Roar - Pre Chorus.midi ├── Sk8er Boi - Verse.midi ├── Treasure - Chorus.midi ├── Treasure - Verse.midi ├── Barbie Girl - Chorus.midi ├── Barbie Girl - Verse.midi ├── Blank Space - Chorus.midi ├── Blank Space - Verse.midi ├── Dark Horse - Chorus.midi ├── Dark Horse - Verse.midi ├── Die Young - Chorus.midi ├── Everybody - Chorus.midi ├── Girl On Fire - Verse.midi ├── Hot N Cold - Bridge.midi ├── Hot N Cold - Chorus.midi ├── Hot N Cold - Verse.midi ├── I Miss You - Chorus.midi ├── I Miss You - Verse.midi ├── Let's Dance - Chorus.midi ├── Love Story - Chorus.midi ├── Love Story - Verse.midi ├── Mr Saxobeat - Verse.midi ├── Piano Man - Chorus.midi ├── Piano man - Bridge.midi ├── Say My Name - Chorus.midi ├── Say My Name - Verse.midi ├── Shake It Off - Verse.midi ├── Tiny Dancer - Chorus.midi ├── Tiny Dancer - Verse.midi ├── Viva La Vida - Verse.midi ├── White Flag - Chorus.midi ├── White Flag - Verse.midi ├── Beautiful Life - Verse.midi ├── Call Me Maybe - Chorus.midi ├── Dancing Queen - Chorus.midi ├── Dancing Queen - Verse.midi ├── Ex's And Oh's - Chorus.midi ├── Feel So Close - Chorus.midi ├── Feel So Close - Verse.midi ├── Girl On Fire - Bridge.midi ├── Girl On Fire - Chorus.midi ├── Irreplaceable - Chorus.midi ├── Shake It Off - Chorus.midi ├── Sweet Nothing - Chorus.midi ├── Sweet Nothing - Verse.midi ├── The Scientist - Intro.midi ├── The Scientist - Verse.midi ├── Around The World - Chorus.midi ├── Around The World - Verse.midi ├── Baby I'm Yours - Chorus.midi ├── Beautiful Life - Chorus.midi ├── Blank Space - Pre Chorus.midi ├── California Gurls - Chorus.midi ├── California Gurls - Verse.midi ├── Don't Trust Me - Chorus.midi ├── Genie in a Bottle - Verse.midi ├── Girl On Fire - Pre Chorus.midi ├── I Gotta Feeling - Chorus.midi ├── I Kissed A Girl - Bridge.midi ├── I Kissed A Girl - Chorus.midi ├── I Kissed A Girl - Verse.midi ├── I Need Your Love - Chorus.midi ├── I Need Your Love - Verse.midi ├── Rock That Body - Chorus.midi ├── Say My Name - Pre Chorus.midi ├── Shake It Off - Pre Chorus.midi ├── Someone Like You - Chorus.midi ├── Someone Like You - Verse.midi ├── The Great Escape - Verse.midi ├── Tiny Dancer - Pre Chorus.midi ├── Titanium feat Sia - Verse.midi ├── Baby One More Time - Chorus.midi ├── Baby One More Time - Verse.midi ├── Beautiful Life - Pre Chorus.midi ├── Chasing Pavements - Chorus.midi ├── Every Time We Touch - Verse.midi ├── Genie In A Bottle - Chorus.midi ├── I Want It That Way - Chorus.midi ├── Put Your Records On - Verse.midi ├── Thinking Out Loud - Chorus.midi ├── Titanium feat Sia - Chorus.midi ├── What A Girl Wants - Chorus.midi ├── When I Was Your Man - Verse.midi ├── You Belong With Me - Chorus.midi ├── You Belong With Me - Verse.midi ├── You Drive Me Crazy - Chorus.midi ├── All The Small Things - Chorus.midi ├── All The Small Things - Verse.midi ├── Best Day Of My Life - Chorus.midi ├── California Gurls - Pre Chorus.midi ├── Every Time We Touch - Chorus.midi ├── How Deep Is Your Love - Chorus.midi ├── Locked Out Of Heaven - Chorus.midi ├── Locked Out Of Heaven - Verse.midi ├── Put Your Records On - Chorus.midi ├── Rolling In The Deep - Chorus.midi ├── When I Was Your Man - Chorus.midi ├── Rolling In The Deep - Pre Chorus.midi ├── When I Was Your Man - Pre Chorus.midi ├── You Belong With Me - Pre Chorus.midi ├── Locked Out Of Heaven - Pre Chorus.midi ├── Can You Feel the Love Tonight - Verse.midi ├── Love Me Harder ft The Weeknd - Chorus.midi ├── Love Me Harder ft The Weeknd - Verse.midi ├── Outside feat Ellie Goulding - Chorus.midi ├── Can You Feel the Love Tonight - Chorus.midi ├── Love Me Harder ft The Weeknd - Pre Chorus.midi └── When Love Takes Over ft Kelly Rowland - Chorus.midi ├── parameter_checkpoints ├── pretrained.ckpt └── initialized.ckpt ├── README.md ├── rnn_rbm_generate.py ├── weight_initializations.py ├── rnn_rbm_train.py ├── RBM.py ├── midi_manipulation.py └── rnn_rbm.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/.DS_Store -------------------------------------------------------------------------------- /Pop_Music_Midi/Roar - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Roar - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Clocks - Intro.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Clocks - Intro.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Clocks - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Clocks - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Fix You - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Fix You - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Pompeii - Intro.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Pompeii - Intro.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Pompeii - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Pompeii - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Roar - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Roar - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Summer - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Summer - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Timber - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Timber - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Timber - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Timber - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Toxic - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Toxic - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Toxic - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Toxic - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Die Young - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Die Young - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Fix You - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Fix You - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Let's Go - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Let's Go - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Piano Man - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Piano Man - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Pompeii - Bridge.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Pompeii - Bridge.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Pompeii - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Pompeii - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Roar - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Roar - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Sk8er Boi - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Sk8er Boi - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Treasure - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Treasure - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Treasure - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Treasure - Verse.midi -------------------------------------------------------------------------------- /parameter_checkpoints/pretrained.ckpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/parameter_checkpoints/pretrained.ckpt -------------------------------------------------------------------------------- /Pop_Music_Midi/Barbie Girl - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Barbie Girl - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Barbie Girl - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Barbie Girl - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Blank Space - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Blank Space - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Blank Space - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Blank Space - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Dark Horse - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Dark Horse - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Dark Horse - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Dark Horse - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Die Young - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Die Young - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Everybody - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Everybody - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Girl On Fire - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Girl On Fire - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Hot N Cold - Bridge.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Hot N Cold - Bridge.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Hot N Cold - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Hot N Cold - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Hot N Cold - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Hot N Cold - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Miss You - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Miss You - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Miss You - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Miss You - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Let's Dance - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Let's Dance - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Love Story - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Love Story - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Love Story - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Love Story - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Mr Saxobeat - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Mr Saxobeat - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Piano Man - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Piano Man - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Piano man - Bridge.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Piano man - Bridge.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Say My Name - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Say My Name - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Say My Name - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Say My Name - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Shake It Off - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Shake It Off - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Tiny Dancer - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Tiny Dancer - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Tiny Dancer - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Tiny Dancer - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Viva La Vida - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Viva La Vida - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/White Flag - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/White Flag - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/White Flag - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/White Flag - Verse.midi -------------------------------------------------------------------------------- /parameter_checkpoints/initialized.ckpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/parameter_checkpoints/initialized.ckpt -------------------------------------------------------------------------------- /Pop_Music_Midi/Beautiful Life - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Beautiful Life - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Call Me Maybe - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Call Me Maybe - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Dancing Queen - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Dancing Queen - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Dancing Queen - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Dancing Queen - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Ex's And Oh's - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Ex's And Oh's - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Feel So Close - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Feel So Close - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Feel So Close - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Feel So Close - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Girl On Fire - Bridge.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Girl On Fire - Bridge.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Girl On Fire - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Girl On Fire - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Irreplaceable - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Irreplaceable - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Shake It Off - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Shake It Off - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Sweet Nothing - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Sweet Nothing - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Sweet Nothing - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Sweet Nothing - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/The Scientist - Intro.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/The Scientist - Intro.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/The Scientist - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/The Scientist - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Around The World - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Around The World - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Around The World - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Around The World - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Baby I'm Yours - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Baby I'm Yours - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Beautiful Life - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Beautiful Life - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Blank Space - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Blank Space - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/California Gurls - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/California Gurls - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/California Gurls - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/California Gurls - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Don't Trust Me - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Don't Trust Me - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Genie in a Bottle - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Genie in a Bottle - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Girl On Fire - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Girl On Fire - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Gotta Feeling - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Gotta Feeling - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Kissed A Girl - Bridge.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Kissed A Girl - Bridge.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Kissed A Girl - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Kissed A Girl - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Kissed A Girl - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Kissed A Girl - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Need Your Love - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Need Your Love - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Need Your Love - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Need Your Love - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Rock That Body - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Rock That Body - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Say My Name - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Say My Name - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Shake It Off - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Shake It Off - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Someone Like You - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Someone Like You - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Someone Like You - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Someone Like You - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/The Great Escape - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/The Great Escape - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Tiny Dancer - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Tiny Dancer - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Titanium feat Sia - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Titanium feat Sia - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Baby One More Time - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Baby One More Time - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Baby One More Time - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Baby One More Time - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Beautiful Life - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Beautiful Life - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Chasing Pavements - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Chasing Pavements - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Every Time We Touch - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Every Time We Touch - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Genie In A Bottle - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Genie In A Bottle - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/I Want It That Way - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/I Want It That Way - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Put Your Records On - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Put Your Records On - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Thinking Out Loud - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Thinking Out Loud - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Titanium feat Sia - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Titanium feat Sia - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/What A Girl Wants - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/What A Girl Wants - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/When I Was Your Man - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/When I Was Your Man - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/You Belong With Me - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/You Belong With Me - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/You Belong With Me - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/You Belong With Me - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/You Drive Me Crazy - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/You Drive Me Crazy - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/All The Small Things - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/All The Small Things - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/All The Small Things - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/All The Small Things - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Best Day Of My Life - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Best Day Of My Life - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/California Gurls - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/California Gurls - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Every Time We Touch - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Every Time We Touch - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/How Deep Is Your Love - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/How Deep Is Your Love - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Locked Out Of Heaven - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Locked Out Of Heaven - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Locked Out Of Heaven - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Locked Out Of Heaven - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Put Your Records On - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Put Your Records On - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Rolling In The Deep - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Rolling In The Deep - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/When I Was Your Man - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/When I Was Your Man - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Rolling In The Deep - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Rolling In The Deep - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/When I Was Your Man - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/When I Was Your Man - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/You Belong With Me - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/You Belong With Me - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Locked Out Of Heaven - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Locked Out Of Heaven - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Can You Feel the Love Tonight - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Can You Feel the Love Tonight - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Love Me Harder ft The Weeknd - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Love Me Harder ft The Weeknd - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Love Me Harder ft The Weeknd - Verse.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Love Me Harder ft The Weeknd - Verse.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Outside feat Ellie Goulding - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Outside feat Ellie Goulding - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Can You Feel the Love Tonight - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Can You Feel the Love Tonight - Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/Love Me Harder ft The Weeknd - Pre Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/Love Me Harder ft The Weeknd - Pre Chorus.midi -------------------------------------------------------------------------------- /Pop_Music_Midi/When Love Takes Over ft Kelly Rowland - Chorus.midi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dshieble/Music_RNN_RBM/HEAD/Pop_Music_Midi/When Love Takes Over ft Kelly Rowland - Chorus.midi -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Note: this is described in detail here: http://danshiebler.com/2016-08-17-musical-tensorflow-part-two-the-rnn-rbm/ 2 | 3 | 4 | # Music_RNN_RBM 5 | 6 | This repository contains code for generating long sequences of polyphonic music by using an RNN_RBM in TensorFlow. 7 | 8 | ### TLDR: 9 | You can generate music by cloning the directory and running: 10 | ``` 11 | python rnn_rbm_generate.py parameter_checkpoints/pretrained.ckpt 12 | ``` 13 | This will populate the music_outputs directory with midi files that you can play with an application like GuitarBand. 14 | 15 | ### Training 16 | To train the model, first run the following command to initialize the parameters of the RBM. 17 | ``` 18 | python weight_initializations.py 19 | ``` 20 | Then, run the following command to train the RNN_RBM model: 21 | ``` 22 | python rnn_rbm_train.py 23 | ``` 24 | `num_epochs` can be any integer. Set it between 50-500, depending on the hyperparameters. 25 | 26 | ### Generation: 27 | The command: 28 | ``` 29 | python rnn_rbm_generate.py 30 | ``` 31 | will generate music by using the weights stored in the `path_to_ckpt_file`. You can use the provided file `parameter_checkpoints/pretrained.ckpt`, or you can use one of the ckpt files that you create. When you run `train_rnn_rbm.py`, the model creates a `epoch_.ckpt` file in the parameter_checkpoints directory every couple of epochs. 32 | 33 | 34 | -------------------------------------------------------------------------------- /rnn_rbm_generate.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import pandas as pd 4 | import sys 5 | import os 6 | from tensorflow.python.ops import control_flow_ops 7 | from tqdm import tqdm 8 | from matplotlib import pyplot as plt 9 | from copy import deepcopy 10 | from tensorflow.examples.tutorials.mnist import input_data 11 | import RBM 12 | import rnn_rbm 13 | import time 14 | import midi_manipulation 15 | 16 | """ 17 | This file contains the code for running a tensorflow session to generate music 18 | """ 19 | 20 | 21 | num = 3 #The number of songs to generate 22 | primer_song = 'Pop_Music_Midi/Every Time We Touch - Chorus.midi' #The path to the song to use to prime the network 23 | 24 | def main(saved_weights_path): 25 | #This function takes as input the path to the weights of the network 26 | x, cost, generate, W, bh, bv, x, lr, Wuh, Wuv, Wvu, Wuu, bu, u0 = rnn_rbm.rnnrbm()#First we build and get the parameters odf the network 27 | 28 | tvars = [W, Wuh, Wuv, Wvu, Wuu, bh, bv, bu, u0] 29 | 30 | saver = tf.train.Saver(tvars) #We use this saver object to restore the weights of the model 31 | 32 | song_primer = midi_manipulation.get_song(primer_song) 33 | 34 | with tf.Session() as sess: 35 | init = tf.initialize_all_variables() 36 | sess.run(init) 37 | saver.restore(sess, saved_weights_path) #load the saved weights of the network 38 | # #We generate num songs 39 | for i in tqdm(range(num)): 40 | generated_music = sess.run(generate(300), feed_dict={x: song_primer}) #Prime the network with song primer and generate an original song 41 | new_song_path = "music_outputs/{}_{}".format(i, primer_song.split("/")[-1]) #The new song will be saved here 42 | midi_manipulation.write_song(new_song_path, generated_music) 43 | 44 | if __name__ == "__main__": 45 | main(sys.argv[1]) 46 | 47 | -------------------------------------------------------------------------------- /weight_initializations.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | from tqdm import tqdm 4 | import RBM 5 | import rnn_rbm #The hyperparameters of the RBM and RNN-RBM are specified in the rnn_rbm file 6 | import midi_manipulation 7 | 8 | """ 9 | This file stores the code for initializing the weights of the RNN-RBM. We initialize the parameters of the RBMs by 10 | training them directly on the data with CD-k. We initialize the parameters of the RNN with small weights. 11 | """ 12 | 13 | num_epochs = 100 #The number of epochs to train the RBM 14 | lr = 0.01 #The learning rate for the RBM 15 | 16 | def main(): 17 | #Load the Songs 18 | songs = midi_manipulation.get_songs('Pop_Music_Midi') 19 | 20 | 21 | x = tf.placeholder(tf.float32, [None, rnn_rbm.n_visible], name="x") #The placeholder variable that holds our data 22 | W = tf.Variable(tf.random_normal([rnn_rbm.n_visible, rnn_rbm.n_hidden], 0.01), name="W") #The weight matrix of the RBM 23 | Wuh = tf.Variable(tf.random_normal([rnn_rbm.n_hidden_recurrent, rnn_rbm.n_hidden], 0.0001), name="Wuh") #The RNN -> RBM hidden weight matrix 24 | bh = tf.Variable(tf.zeros([1, rnn_rbm.n_hidden], tf.float32), name="bh") #The RNN -> RBM hidden bias vector 25 | Wuv = tf.Variable(tf.random_normal([rnn_rbm.n_hidden_recurrent, rnn_rbm.n_visible], 0.0001), name="Wuv") #The RNN -> RBM visible weight matrix 26 | bv = tf.Variable(tf.zeros([1, rnn_rbm.n_visible], tf.float32), name="bv")#The RNN -> RBM visible bias vector 27 | Wvu = tf.Variable(tf.random_normal([rnn_rbm.n_visible, rnn_rbm.n_hidden_recurrent], 0.0001), name="Wvu") #The data -> RNN weight matrix 28 | Wuu = tf.Variable(tf.random_normal([rnn_rbm.n_hidden_recurrent, rnn_rbm.n_hidden_recurrent], 0.0001), name="Wuu") #The RNN hidden unit weight matrix 29 | bu = tf.Variable(tf.zeros([1, rnn_rbm.n_hidden_recurrent], tf.float32), name="bu") #The RNN hidden unit bias vector 30 | u0 = tf.Variable(tf.zeros([1, rnn_rbm.n_hidden_recurrent], tf.float32), name="u0") #The initial state of the RNN 31 | 32 | #The RBM bias vectors. These matrices will get populated during rnn-rbm training and generation 33 | BH_t = tf.Variable(tf.ones([1, rnn_rbm.n_hidden], tf.float32), name="BH_t") 34 | BV_t = tf.Variable(tf.ones([1, rnn_rbm.n_visible], tf.float32), name="BV_t") 35 | 36 | #Build the RBM optimization 37 | saver = tf.train.Saver() 38 | 39 | #Note that we initialize the RNN->RBM bias vectors with the bias vectors of the trained RBM. These vectors will form the templates for the bv_t and 40 | #bh_t of each RBM that we create when we run the RNN-RBM 41 | updt = RBM.get_cd_update(x, W, bv, bh, 1, lr) 42 | 43 | #Run the session 44 | with tf.Session() as sess: 45 | #Initialize the variables of the model 46 | init = tf.initialize_all_variables() 47 | sess.run(init) 48 | 49 | #Run over each song num_epoch times 50 | for epoch in tqdm(range(num_epochs)): 51 | for song in songs: 52 | sess.run(updt, feed_dict={x: song}) 53 | #Save the initialized model here 54 | save_path = saver.save(sess, "parameter_checkpoints/initialized.ckpt") 55 | 56 | if __name__ == "__main__": 57 | main() 58 | -------------------------------------------------------------------------------- /rnn_rbm_train.py: -------------------------------------------------------------------------------- 1 | import time 2 | import sys 3 | import tensorflow as tf 4 | import numpy as np 5 | from tqdm import tqdm 6 | import rnn_rbm 7 | import midi_manipulation 8 | 9 | """ 10 | This file contains the code for training the RNN-RBM by using the data in the Pop_Music_Midi directory 11 | """ 12 | 13 | 14 | batch_size = 100 #The number of trianing examples to feed into the rnn_rbm at a time 15 | epochs_to_save = 5 #The number of epochs to run between saving each checkpoint 16 | saved_weights_path = "parameter_checkpoints/initialized.ckpt" #The path to the initialized weights checkpoint file 17 | 18 | def main(num_epochs): 19 | #First, we build the model and get pointers to the model parameters 20 | x, cost, generate, W, bh, bv, x, lr, Wuh, Wuv, Wvu, Wuu, bu, u0 = rnn_rbm.rnnrbm() 21 | 22 | #The trainable variables include the weights and biases of the RNN and the RBM, as well as the initial state of the RNN 23 | tvars = [W, Wuh, Wuv, Wvu, Wuu, bh, bv, bu, u0] 24 | # opt_func = tf.train.AdamOptimizer(learning_rate=lr) 25 | # grads, _ = tf.clip_by_global_norm(tf.gradients(cost, tvars), 1) 26 | # updt = opt_func.apply_gradients(zip(grads, tvars)) 27 | 28 | #The learning rate of the optimizer is a parameter that we set on a schedule during training 29 | opt_func = tf.train.GradientDescentOptimizer(learning_rate=lr) 30 | gvs = opt_func.compute_gradients(cost, tvars) 31 | gvs = [(tf.clip_by_value(grad, -10., 10.), var) for grad, var in gvs] #We use gradient clipping to prevent gradients from blowing up during training 32 | updt = opt_func.apply_gradients(gvs)#The update step involves applying the clipped gradients to the model parameters 33 | 34 | songs = midi_manipulation.get_songs('Pop_Music_Midi') #Load the songs 35 | 36 | saver = tf.train.Saver(tvars) #We use this saver object to restore the weights of the model and save the weights every few epochs 37 | with tf.Session() as sess: 38 | init = tf.initialize_all_variables() 39 | sess.run(init) 40 | saver.restore(sess, saved_weights_path) #Here we load the initial weights of the model that we created with weight_initializations.py 41 | 42 | #We run through all of the songs n_epoch times 43 | print "starting" 44 | for epoch in range(num_epochs): 45 | costs = [] 46 | start = time.time() 47 | for s_ind, song in enumerate(songs): 48 | for i in range(1, len(song), batch_size): 49 | tr_x = song[i:i + batch_size] 50 | alpha = min(0.01, 0.1/float(i)) #We decrease the learning rate according to a schedule. 51 | _, C = sess.run([updt, cost], feed_dict={x: tr_x, lr: alpha}) 52 | costs.append(C) 53 | #Print the progress at epoch 54 | print "epoch: {} cost: {} time: {}".format(epoch, np.mean(costs), time.time()-start) 55 | print 56 | #Here we save the weights of the model every few epochs 57 | if (epoch + 1) % epochs_to_save == 0: 58 | saver.save(sess, "parameter_checkpoints/epoch_{}.ckpt".format(epoch)) 59 | 60 | if __name__ == "__main__": 61 | main(int(sys.argv[1])) 62 | 63 | 64 | -------------------------------------------------------------------------------- /RBM.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from tensorflow.python.ops import control_flow_ops 3 | import numpy as np 4 | import pandas as pd 5 | 6 | 7 | """ 8 | This file contains the TF implementation of the Restricted Boltzman Machine 9 | """ 10 | 11 | 12 | #This function lets us easily sample from a vector of probabilities 13 | def sample(probs): 14 | #Takes in a vector of probabilities, and returns a random vector of 0s and 1s sampled from the input vector 15 | return tf.floor(probs + tf.random_uniform(tf.shape(probs), 0, 1)) 16 | 17 | #This function runs the gibbs chain. We will call this function in two places: 18 | # - When we define the training update step 19 | # - When we sample our music segments from the trained RBM 20 | def gibbs_sample(x, W, bv, bh, k): 21 | #Runs a k-step gibbs chain to sample from the probability distribution of the RBM defined by W, bh, bv 22 | def gibbs_step(count, k, xk): 23 | #Runs a single gibbs step. The visible values are initialized to xk 24 | hk = sample(tf.sigmoid(tf.matmul(xk, W) + bh)) #Propagate the visible values to sample the hidden values 25 | xk = sample(tf.sigmoid(tf.matmul(hk, tf.transpose(W)) + bv)) #Propagate the hidden values to sample the visible values 26 | return count+1, k, xk 27 | 28 | #Run gibbs steps for k iterations 29 | ct = tf.constant(0) #counter 30 | [_, _, x_sample] = control_flow_ops.While(lambda count, num_iter, *args: count < num_iter, 31 | gibbs_step, [ct, tf.constant(k), x], 1, False) 32 | #We need this in order to stop tensorflow from propagating gradients back through the gibbs step 33 | x_sample = tf.stop_gradient(x_sample) 34 | return x_sample 35 | 36 | def get_free_energy_cost(x, W, bv, bh, k): 37 | #We use this function in training to get the free energy cost of the RBM. We can pass this cost directly into TensorFlow's optimizers 38 | #First, draw a sample from the RBM 39 | x_sample = gibbs_sample(x, W, bv, bh, k) 40 | 41 | def F(xx): 42 | #The function computes the free energy of a visible vector. 43 | return -tf.reduce_sum(tf.log(1 + tf.exp(tf.matmul(xx, W) + bh)), 1) - tf.matmul(xx, tf.transpose(bv)) 44 | 45 | #The cost is based on the difference in free energy between x and xsample 46 | cost = tf.reduce_mean(tf.sub(F(x), F(x_sample))) 47 | return cost 48 | 49 | def get_cd_update(x, W, bv, bh, k, lr): 50 | #This is the contrastive divergence algorithm. 51 | 52 | #First, we get the samples of x and h from the probability distribution 53 | #The sample of x 54 | x_sample = gibbs_sample(x, W, bv, bh, k) 55 | #The sample of the hidden nodes, starting from the visible state of x 56 | h = sample(tf.sigmoid(tf.matmul(x, W) + bh)) 57 | #The sample of the hidden nodes, starting from the visible state of x_sample 58 | h_sample = sample(tf.sigmoid(tf.matmul(x_sample, W) + bh)) 59 | 60 | #Next, we update the values of W, bh, and bv, based on the difference between the samples that we drew and the original values 61 | lr = tf.constant(lr, tf.float32) #The CD learning rate 62 | size_bt = tf.cast(tf.shape(x)[0], tf.float32) #The batch size 63 | W_ = tf.mul(lr/size_bt, tf.sub(tf.matmul(tf.transpose(x), h), tf.matmul(tf.transpose(x_sample), h_sample))) 64 | bv_ = tf.mul(lr/size_bt, tf.reduce_sum(tf.sub(x, x_sample), 0, True)) 65 | bh_ = tf.mul(lr/size_bt, tf.reduce_sum(tf.sub(h, h_sample), 0, True)) 66 | 67 | #When we do sess.run(updt), TensorFlow will run all 3 update steps 68 | updt = [W.assign_add(W_), bv.assign_add(bv_), bh.assign_add(bh_)] 69 | return updt 70 | 71 | -------------------------------------------------------------------------------- /midi_manipulation.py: -------------------------------------------------------------------------------- 1 | import midi 2 | import numpy as np 3 | import glob 4 | from tqdm import tqdm 5 | 6 | lowerBound = 24 #The lowest note 7 | upperBound = 102 #The highest note 8 | span = upperBound-lowerBound #The note range 9 | num_timesteps = 5 #The number of note timesteps that we produce with each RBM 10 | 11 | 12 | def write_song(path, song): 13 | #Reshape the song into a format that midi_manipulation can understand, and then write the song to disk 14 | song = np.reshape(song, (song.shape[0]*num_timesteps, 2*span)) 15 | noteStateMatrixToMidi(song, name=path) 16 | 17 | def get_song(path): 18 | #Load the song and reshape it to place multiple timesteps next to each other 19 | song = np.array(midiToNoteStateMatrix(path)) 20 | song = song[:np.floor(song.shape[0]/num_timesteps)*num_timesteps] 21 | song = np.reshape(song, [song.shape[0]/num_timesteps, song.shape[1]*num_timesteps]) 22 | return song 23 | 24 | def get_songs(path): 25 | files = glob.glob('{}/*.mid*'.format(path)) 26 | songs = [] 27 | for f in tqdm(files): 28 | try: 29 | song = get_song(f) 30 | if np.array(song).shape[0] > 50/num_timesteps: 31 | songs.append(song) 32 | except Exception as e: 33 | print f, e 34 | return songs 35 | 36 | def midiToNoteStateMatrix(midifile, squash=True, span=span): 37 | pattern = midi.read_midifile(midifile) 38 | 39 | timeleft = [track[0].tick for track in pattern] 40 | 41 | posns = [0 for track in pattern] 42 | 43 | statematrix = [] 44 | time = 0 45 | 46 | state = [[0,0] for x in range(span)] 47 | statematrix.append(state) 48 | condition = True 49 | while condition: 50 | if time % (pattern.resolution / 4) == (pattern.resolution / 8): 51 | # Crossed a note boundary. Create a new state, defaulting to holding notes 52 | oldstate = state 53 | state = [[oldstate[x][0],0] for x in range(span)] 54 | statematrix.append(state) 55 | for i in range(len(timeleft)): #For each track 56 | if not condition: 57 | break 58 | while timeleft[i] == 0: 59 | track = pattern[i] 60 | pos = posns[i] 61 | 62 | evt = track[pos] 63 | if isinstance(evt, midi.NoteEvent): 64 | if (evt.pitch < lowerBound) or (evt.pitch >= upperBound): 65 | pass 66 | # print "Note {} at time {} out of bounds (ignoring)".format(evt.pitch, time) 67 | else: 68 | if isinstance(evt, midi.NoteOffEvent) or evt.velocity == 0: 69 | state[evt.pitch-lowerBound] = [0, 0] 70 | else: 71 | state[evt.pitch-lowerBound] = [1, 1] 72 | elif isinstance(evt, midi.TimeSignatureEvent): 73 | if evt.numerator not in (2, 4): 74 | # We don't want to worry about non-4 time signatures. Bail early! 75 | # print "Found time signature event {}. Bailing!".format(evt) 76 | out = statematrix 77 | condition = False 78 | break 79 | try: 80 | timeleft[i] = track[pos + 1].tick 81 | posns[i] += 1 82 | except IndexError: 83 | timeleft[i] = None 84 | 85 | if timeleft[i] is not None: 86 | timeleft[i] -= 1 87 | 88 | if all(t is None for t in timeleft): 89 | break 90 | 91 | time += 1 92 | 93 | S = np.array(statematrix) 94 | statematrix = np.hstack((S[:, :, 0], S[:, :, 1])) 95 | statematrix = np.asarray(statematrix).tolist() 96 | return statematrix 97 | 98 | def noteStateMatrixToMidi(statematrix, name="example", span=span): 99 | statematrix = np.array(statematrix) 100 | if not len(statematrix.shape) == 3: 101 | statematrix = np.dstack((statematrix[:, :span], statematrix[:, span:])) 102 | statematrix = np.asarray(statematrix) 103 | pattern = midi.Pattern() 104 | track = midi.Track() 105 | pattern.append(track) 106 | 107 | span = upperBound-lowerBound 108 | tickscale = 55 109 | 110 | lastcmdtime = 0 111 | prevstate = [[0,0] for x in range(span)] 112 | for time, state in enumerate(statematrix + [prevstate[:]]): 113 | offNotes = [] 114 | onNotes = [] 115 | for i in range(span): 116 | n = state[i] 117 | p = prevstate[i] 118 | if p[0] == 1: 119 | if n[0] == 0: 120 | offNotes.append(i) 121 | elif n[1] == 1: 122 | offNotes.append(i) 123 | onNotes.append(i) 124 | elif n[0] == 1: 125 | onNotes.append(i) 126 | for note in offNotes: 127 | track.append(midi.NoteOffEvent(tick=(time-lastcmdtime)*tickscale, pitch=note+lowerBound)) 128 | lastcmdtime = time 129 | for note in onNotes: 130 | track.append(midi.NoteOnEvent(tick=(time-lastcmdtime)*tickscale, velocity=40, pitch=note+lowerBound)) 131 | lastcmdtime = time 132 | 133 | prevstate = state 134 | 135 | eot = midi.EndOfTrackEvent(tick=1) 136 | track.append(eot) 137 | 138 | midi.write_midifile("{}.mid".format(name), pattern) -------------------------------------------------------------------------------- /rnn_rbm.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import glob 4 | 5 | from tensorflow.python.ops import control_flow_ops 6 | from tqdm import tqdm 7 | 8 | import RBM 9 | import midi_manipulation 10 | 11 | 12 | """ 13 | This file contains the TF implementation of the RNN-RBM, as well as the hyperparameters of the model 14 | """ 15 | 16 | note_range = midi_manipulation.span #The range of notes that we can produce 17 | n_visible = 2*note_range*midi_manipulation.num_timesteps #The size of each data vector and the size of the RBM visible layer 18 | n_hidden = 50 #The size of the RBM hidden layer 19 | n_hidden_recurrent = 100 #The size of each RNN hidden layer 20 | 21 | def rnnrbm(): 22 | 23 | #This function builds the RNN-RBM and returns the parameters of the model 24 | 25 | x = tf.placeholder(tf.float32, [None, n_visible]) #The placeholder variable that holds our data 26 | lr = tf.placeholder(tf.float32) #The learning rate. We set and change this value during training. 27 | 28 | size_bt = tf.shape(x)[0] #the batch size 29 | 30 | #Here we set aside the space for each of the variables. 31 | #We intialize these variables when we load saved parameters in rnn_rbm_train.py or rnn_rbm_generate.py 32 | W = tf.Variable(tf.zeros([n_visible, n_hidden]), name="W") 33 | Wuh = tf.Variable(tf.zeros([n_hidden_recurrent, n_hidden]), name="Wuh") 34 | Wuv = tf.Variable(tf.zeros([n_hidden_recurrent, n_visible]), name="Wuv") 35 | Wvu = tf.Variable(tf.zeros([n_visible, n_hidden_recurrent]), name="Wvu") 36 | Wuu = tf.Variable(tf.zeros([n_hidden_recurrent, n_hidden_recurrent]), name="Wuu") 37 | bh = tf.Variable(tf.zeros([1, n_hidden]), name="bh") 38 | bv = tf.Variable(tf.zeros([1, n_visible]), name="bv") 39 | bu = tf.Variable(tf.zeros([1, n_hidden_recurrent]), name="bu") 40 | u0 = tf.Variable(tf.zeros([1, n_hidden_recurrent]), name="u0") 41 | BH_t = tf.Variable(tf.zeros([1, n_hidden]), name="BH_t") 42 | BV_t = tf.Variable(tf.zeros([1, n_visible]), name="BV_t") 43 | 44 | 45 | def rnn_recurrence(u_tm1, sl): 46 | #Iterate through the data in the batch and generate the values of the RNN hidden nodes 47 | sl = tf.reshape(sl, [1, n_visible]) 48 | u_t = (tf.tanh(bu + tf.matmul(sl, Wvu) + tf.matmul(u_tm1, Wuu))) 49 | return u_t 50 | 51 | def visible_bias_recurrence(bv_t, u_tm1): 52 | #Iterate through the values of the RNN hidden nodes and generate the values of the visible bias vectors 53 | bv_t = tf.add(bv, tf.matmul(u_tm1, Wuv)) 54 | return bv_t 55 | 56 | def hidden_bias_recurrence(bh_t, u_tm1): 57 | #Iterate through the values of the RNN hidden nodes and generate the values of the hidden bias vectors 58 | bh_t = tf.add(bh, tf.matmul(u_tm1, Wuh)) 59 | return bh_t 60 | 61 | def generate_recurrence(count, k, u_tm1, primer, x, music): 62 | #This function builds and runs the gibbs steps for each RBM in the chain to generate music 63 | #Get the bias vectors from the current state of the RNN 64 | bv_t = tf.add(bv, tf.matmul(u_tm1, Wuv)) 65 | bh_t = tf.add(bh, tf.matmul(u_tm1, Wuh)) 66 | 67 | #Run the Gibbs step to get the music output. Prime the RBM with the previous musical output. 68 | x_out = RBM.gibbs_sample(primer, W, bv_t, bh_t, k=25) 69 | 70 | #Update the RNN hidden state based on the musical output and current hidden state. 71 | u_t = (tf.tanh(bu + tf.matmul(x_out, Wvu) + tf.matmul(u_tm1, Wuu))) 72 | 73 | #Add the new output to the musical piece 74 | music = tf.concat(0, [music, x_out]) 75 | return count+1, k, u_t, x_out, x, music 76 | 77 | def generate(num, x=x, size_bt=size_bt, u0=u0, n_visible=n_visible, prime_length=100): 78 | """ 79 | This function handles generating music. This function is one of the outputs of the build_rnnrbm function 80 | Args: 81 | num (int): The number of timesteps to generate 82 | x (tf.placeholder): The data vector. We can use feed_dict to set this to the music primer. 83 | size_bt (tf.float32): The batch size 84 | u0 (tf.Variable): The initial state of the RNN 85 | n_visible (int): The size of the data vectors 86 | prime_length (int): The number of timesteps into the primer song that we use befoe beginning to generate music 87 | Returns: 88 | The generated music, as a tf.Tensor 89 | 90 | """ 91 | Uarr = tf.scan(rnn_recurrence, x, initializer=u0) 92 | U = Uarr[np.floor(prime_length/midi_manipulation.num_timesteps), :, :] 93 | [_, _, _, _, _, music] = control_flow_ops.While(lambda count, num_iter, *args: count < num_iter, 94 | generate_recurrence, [tf.constant(1, tf.int32), tf.constant(num), U, 95 | tf.zeros([1, n_visible], tf.float32), x, 96 | tf.zeros([1, n_visible], tf.float32)]) 97 | return music 98 | 99 | #Reshape our bias matrices to be the same size as the batch. 100 | tf.assign(BH_t, tf.tile(BH_t, [size_bt, 1])) 101 | tf.assign(BV_t, tf.tile(BV_t, [size_bt, 1])) 102 | #Scan through the rnn and generate the value for each hidden node in the batch 103 | u_t = tf.scan(rnn_recurrence, x, initializer=u0) 104 | #Scan through the rnn and generate the visible and hidden biases for each RBM in the batch 105 | BV_t = tf.reshape(tf.scan(visible_bias_recurrence, u_t, tf.zeros([1, n_visible], tf.float32)), [size_bt, n_visible]) 106 | BH_t = tf.reshape(tf.scan(hidden_bias_recurrence, u_t, tf.zeros([1, n_hidden], tf.float32)), [size_bt, n_hidden]) 107 | #Get the free energy cost from each of the RBMs in the batch 108 | cost = RBM.get_free_energy_cost(x, W, BV_t, BH_t, k=15) 109 | return x, cost, generate, W, bh, bv, x, lr, Wuh, Wuv, Wvu, Wuu, bu, u0 110 | 111 | --------------------------------------------------------------------------------