Skip to content

Commit

Permalink
Prelim. Version 0.7. Encoder is done. Working on Decoder...
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Oct 11, 2020
1 parent e5907f1 commit 23a2274
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions DOREMI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,19 @@
"cellView": "form"
},
"source": [
"#@title Install dependencies, import modules, check GPU\n",
"#@title Install dependencies, import modules, set GPU, create MIDI Dataset dir\n",
"!pip install miditoolkit\n",
"import miditoolkit\n",
"import numpy as np\n",
"import os\n",
"from os import listdir\n",
"from os.path import isfile, join\n",
"os.environ['CUDA_VISIBLE_DEVICES'] = '0'\n",
"import copy"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "m054X5rd2ARx",
"cellView": "form"
},
"source": [
"#@title (Best Choice/Works best stand-alone) Alex Piano Only Drafts Original 1500 MIDIs \n",
"!wget 'https://github.com/asigalov61/AlexMIDIDataSet/raw/master/AlexMIDIDataSet-CC-BY-NC-SA-All-Drafts-Piano-Only.zip'\n",
"!unzip -j 'AlexMIDIDataSet-CC-BY-NC-SA-All-Drafts-Piano-Only.zip'"
"import copy\n",
"import glob\n",
"import tqdm.auto\n",
"if not os.path.exists('/content/midis'):\n",
" os.makedirs('/content/midis')"
],
"execution_count": null,
"outputs": []
Expand Down Expand Up @@ -651,15 +643,11 @@
},
"source": [
"#@title Calculate Number of Indexable MIDI files :)\n",
"import os\n",
"from os import listdir\n",
"from os.path import isfile, join\n",
"\n",
"# Modify these paths to your own MIDI Dataset\n",
"data_dirs = ['/content/midis']\n",
"\n",
"if not os.path.exists('/content/midis'):\n",
" os.makedirs('/content/midis')\n",
"\n",
"\n",
"data_files = []\n",
"for data_dir in data_dirs:\n",
Expand All @@ -680,28 +668,45 @@
},
"source": [
"#@title Convert MIDIs to REMI and then TXT\n",
"from tqdm import tqdm_notebook as tqdm\n",
"import os\n",
"import numpy as np\n",
"\n",
"\n",
"dataset_dir = 'dataset'\n",
"#os.chdir('remi')\n",
"\n",
"if not os.path.exists(dataset_dir):\n",
" os.makedirs(dataset_dir)\n",
"\n",
"for i in tqdm(range(len(data_files))):\n",
"for i in tqdm.auto.tqdm(range(len(data_files))):\n",
" print(data_files[i])\n",
" eventlist = get_events_from_midis(data_files[i])\n",
" #eventlist = events\n",
" #print(eventlist)\n",
" \n",
" save_file = dataset_dir + '/' + str(i)\n",
" save_file = dataset_dir + '/' + str(i) + '.txt'\n",
" data = {'eventlist': eventlist}\n",
" #np.savez(save_file, **data, allow_pickle=False)\n",
" #np.savetxt(save_file, eventlist, delimiter=',')\n",
"with open('output.txt', 'w') as midi_file:\n",
" midi_file.write(str(eventlist))\n",
" midi_file.close()\n",
" np.savetxt(save_file, eventlist, fmt='%s', delimiter=',')\n",
"\n",
"# Creating a list of TXT filenames \n",
"\n",
"os.chdir('dataset')\n",
"\n",
"# Open file3 in write mode \n",
"if os.path.exists(\"Dataset.txt\"):\n",
" os.remove(\"Dataset.txt\")\n",
" print('Removing old Dataset...')\n",
"else:\n",
" print(\"Creating new Dataset file...\")\n",
"read_files = glob.glob(\"*.txt\")\n",
"with open('Dataset.txt', 'w') as outfile: \n",
" \n",
" # Iterate through list \n",
" for names in read_files: \n",
" \n",
" # Open each file in read mode \n",
" with open(names) as infile: \n",
" outfile.write(infile.read()) \n",
"\n",
"os.chdir('/content/')\n",
"print('Done!')"
],
"execution_count": null,
Expand Down

0 comments on commit 23a2274

Please sign in to comment.