projectlosangeles commited on
Commit
66d2690
1 Parent(s): b933703

Upload 3 files

Browse files
Master_MIDI_Dataset_GPU_Search_and_Filter.ipynb CHANGED
@@ -11,7 +11,7 @@
11
  "id": "SiTIpPjArIyr"
12
  },
13
  "source": [
14
- "# Master MIDI Dataset GPU Search and Filter (ver. 6.0)\n",
15
  "\n",
16
  "***\n",
17
  "\n",
@@ -282,7 +282,7 @@
282
  "print('Loading signatures...')\n",
283
  "print('=' * 70)\n",
284
  "\n",
285
- "signatures_data = cp.array(sigs_matrixes)\n",
286
  "\n",
287
  "print('Done!')\n",
288
  "print('=' * 70)"
@@ -319,6 +319,25 @@
319
  "\n",
320
  "###########\n",
321
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  "print('Loading MIDI files...')\n",
323
  "print('This may take a while on a large dataset in particular.')\n",
324
  "\n",
@@ -341,8 +360,8 @@
341
  "\n",
342
  " ###################\n",
343
  "\n",
344
- " if not os.path.exists('/content/Output-MIDI-Dataset/'+search_matching_type):\n",
345
- " os.makedirs('/content/Output-MIDI-Dataset/'+search_matching_type)\n",
346
  "\n",
347
  " ###################\n",
348
  "\n",
@@ -390,7 +409,7 @@
390
  " for c in cscore:\n",
391
  "\n",
392
  " pitches = sorted(set([p[4] for p in c if p[3] != 9]))\n",
393
- " drums = sorted(set([p[4] for p in c if p[3] == 9]))\n",
394
  "\n",
395
  " if pitches:\n",
396
  " if len(pitches) > 1:\n",
@@ -424,7 +443,10 @@
424
  " src_signatures = cp.stack(cp.array(src_sigs))\n",
425
  "\n",
426
  " if not match_drums:\n",
427
- " src_signatures = cp.where(src_signatures < drums_offset, src_signatures, epsilon)\n",
 
 
 
428
  "\n",
429
  " #=======================================================\n",
430
  "\n",
@@ -447,9 +469,6 @@
447
  "\n",
448
  " for target_sig in tqdm(src_signatures):\n",
449
  "\n",
450
- " if not match_drums:\n",
451
- " target_sig = cp.where(target_sig < drums_offset, target_sig, epsilon)\n",
452
- "\n",
453
  " comps_lengths = cp.vstack((cp.repeat(cp.sum(target_sig != 0), signatures_data.shape[0]), cp.sum(signatures_data != 0, axis=1)))\n",
454
  " comps_lengths_ratios = cp.divide(cp.min(comps_lengths, axis=0), cp.max(comps_lengths, axis=0))\n",
455
  "\n",
@@ -496,9 +515,9 @@
496
  "\n",
497
  " filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]\n",
498
  "\n",
499
- " filtered_idxs = cp.where(cp.in1d(results, filtered_means))[0]\n",
500
  "\n",
501
- " all_filtered_means.extend(results[cp.in1d(results, filtered_means)].tolist())\n",
502
  "\n",
503
  " all_filtered_idxs.extend(filtered_idxs.tolist())\n",
504
  "\n",
@@ -545,7 +564,7 @@
545
  " #=======================================================\n",
546
  "\n",
547
  " dir_str = str(fn1)\n",
548
- " copy_path = '/content/Output-MIDI-Dataset/'+search_matching_type+'/'+dir_str\n",
549
  " if not os.path.exists(copy_path):\n",
550
  " os.mkdir(copy_path)\n",
551
  "\n",
@@ -678,9 +697,9 @@
678
  "\n",
679
  "number_of_top_matches_MIDIs_to_collect = 30 #@param {type:\"slider\", min:5, max:50, step:1}\n",
680
  "maximum_match_ratio_to_search_for = 1 #@param {type:\"slider\", min:0, max:1, step:0.001}\n",
681
- "match_results_weight = 1 # @param {type:\"slider\", min:0.1, max:3, step:0.1}\n",
682
- "match_lengths_weight = 0.5 # @param {type:\"slider\", min:0.1, max:3, step:0.1}\n",
683
- "match_counts_weight = 0.5 # @param {type:\"slider\", min:0.1, max:3, step:0.1}\n",
684
  "epsilon = 0.5 # @param {type:\"slider\", min:0.001, max:1, step:0.001}\n",
685
  "\n",
686
  "print('=' * 70)\n",
@@ -689,6 +708,19 @@
689
  "\n",
690
  "###########\n",
691
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  "print('Loading MIDI files...')\n",
693
  "print('This may take a while on a large dataset in particular.')\n",
694
  "\n",
@@ -711,8 +743,8 @@
711
  "\n",
712
  " ###################\n",
713
  "\n",
714
- " if not os.path.exists('/content/Output-MIDI-Dataset/'+search_matching_type):\n",
715
- " os.makedirs('/content/Output-MIDI-Dataset/'+search_matching_type)\n",
716
  "\n",
717
  " ###################\n",
718
  "\n",
@@ -828,9 +860,9 @@
828
  "\n",
829
  " filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]\n",
830
  "\n",
831
- " filtered_idxs = cp.where(cp.in1d(results, filtered_means))[0]\n",
832
  "\n",
833
- " all_filtered_means.extend(results[cp.in1d(results, filtered_means)].tolist())\n",
834
  "\n",
835
  " all_filtered_idxs.extend(filtered_idxs.tolist())\n",
836
  "\n",
@@ -877,7 +909,7 @@
877
  " #=======================================================\n",
878
  "\n",
879
  " dir_str = str(fn1)\n",
880
- " copy_path = '/content/Output-MIDI-Dataset/'+search_matching_type+'/'+dir_str\n",
881
  " if not os.path.exists(copy_path):\n",
882
  " os.mkdir(copy_path)\n",
883
  "\n",
 
11
  "id": "SiTIpPjArIyr"
12
  },
13
  "source": [
14
+ "# Master MIDI Dataset GPU Search and Filter (ver. 7.0)\n",
15
  "\n",
16
  "***\n",
17
  "\n",
 
282
  "print('Loading signatures...')\n",
283
  "print('=' * 70)\n",
284
  "\n",
285
+ "signatures_data_full = cp.array(sigs_matrixes)\n",
286
  "\n",
287
  "print('Done!')\n",
288
  "print('=' * 70)"
 
319
  "\n",
320
  "###########\n",
321
  "\n",
322
+ "search_settings_string = ''\n",
323
+ "\n",
324
+ "if match_drums:\n",
325
+ " search_settings_string += 'Chords_Drums'\n",
326
+ "else:\n",
327
+ " search_settings_string += 'Chords'\n",
328
+ "\n",
329
+ "if search_matching_type == 'Distances':\n",
330
+ " search_settings_string += '_O_' + str(distances_norm_order)\n",
331
+ "\n",
332
+ "search_settings_string += '_W_'\n",
333
+ "search_settings_string += str(match_results_weight) + '_'\n",
334
+ "search_settings_string += str(match_lengths_weight) + '_'\n",
335
+ "search_settings_string += str(match_counts_weight)\n",
336
+ "\n",
337
+ "search_settings_string += '_E_' + str(epsilon)\n",
338
+ "\n",
339
+ "###########\n",
340
+ "\n",
341
  "print('Loading MIDI files...')\n",
342
  "print('This may take a while on a large dataset in particular.')\n",
343
  "\n",
 
360
  "\n",
361
  " ###################\n",
362
  "\n",
363
+ " if not os.path.exists('/content/Output-MIDI-Dataset/'+search_matching_type+'_'+search_settings_string):\n",
364
+ " os.makedirs('/content/Output-MIDI-Dataset/'+search_matching_type+'_'+search_settings_string)\n",
365
  "\n",
366
  " ###################\n",
367
  "\n",
 
409
  " for c in cscore:\n",
410
  "\n",
411
  " pitches = sorted(set([p[4] for p in c if p[3] != 9]))\n",
412
+ " drums = sorted(set([p[4]+drums_offset for p in c if p[3] == 9]))\n",
413
  "\n",
414
  " if pitches:\n",
415
  " if len(pitches) > 1:\n",
 
443
  " src_signatures = cp.stack(cp.array(src_sigs))\n",
444
  "\n",
445
  " if not match_drums:\n",
446
+ " src_signatures = src_signatures[:,:drums_offset]\n",
447
+ " signatures_data = signatures_data_full[:,:drums_offset]\n",
448
+ " else:\n",
449
+ " signatures_data = signatures_data_full\n",
450
  "\n",
451
  " #=======================================================\n",
452
  "\n",
 
469
  "\n",
470
  " for target_sig in tqdm(src_signatures):\n",
471
  "\n",
 
 
 
472
  " comps_lengths = cp.vstack((cp.repeat(cp.sum(target_sig != 0), signatures_data.shape[0]), cp.sum(signatures_data != 0, axis=1)))\n",
473
  " comps_lengths_ratios = cp.divide(cp.min(comps_lengths, axis=0), cp.max(comps_lengths, axis=0))\n",
474
  "\n",
 
515
  "\n",
516
  " filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]\n",
517
  "\n",
518
+ " filtered_idxs = cp.nonzero(cp.in1d(results, filtered_means))[0]\n",
519
  "\n",
520
+ " all_filtered_means.extend(results[filtered_idxs].tolist())\n",
521
  "\n",
522
  " all_filtered_idxs.extend(filtered_idxs.tolist())\n",
523
  "\n",
 
564
  " #=======================================================\n",
565
  "\n",
566
  " dir_str = str(fn1)\n",
567
+ " copy_path = '/content/Output-MIDI-Dataset/'+search_matching_type+'_'+search_settings_string+'/'+dir_str\n",
568
  " if not os.path.exists(copy_path):\n",
569
  " os.mkdir(copy_path)\n",
570
  "\n",
 
697
  "\n",
698
  "number_of_top_matches_MIDIs_to_collect = 30 #@param {type:\"slider\", min:5, max:50, step:1}\n",
699
  "maximum_match_ratio_to_search_for = 1 #@param {type:\"slider\", min:0, max:1, step:0.001}\n",
700
+ "match_results_weight = 2 # @param {type:\"slider\", min:0.1, max:3, step:0.1}\n",
701
+ "match_lengths_weight = 1 # @param {type:\"slider\", min:0.1, max:3, step:0.1}\n",
702
+ "match_counts_weight = 1 # @param {type:\"slider\", min:0.1, max:3, step:0.1}\n",
703
  "epsilon = 0.5 # @param {type:\"slider\", min:0.001, max:1, step:0.001}\n",
704
  "\n",
705
  "print('=' * 70)\n",
 
708
  "\n",
709
  "###########\n",
710
  "\n",
711
+ "search_settings_string = ''\n",
712
+ "\n",
713
+ "search_settings_string += str(search_matching_type).replace('-', '_')\n",
714
+ "\n",
715
+ "search_settings_string += '_W_'\n",
716
+ "search_settings_string += str(match_results_weight) + '_'\n",
717
+ "search_settings_string += str(match_lengths_weight) + '_'\n",
718
+ "search_settings_string += str(match_counts_weight)\n",
719
+ "\n",
720
+ "search_settings_string += '_E_' + str(epsilon)\n",
721
+ "\n",
722
+ "###########\n",
723
+ "\n",
724
  "print('Loading MIDI files...')\n",
725
  "print('This may take a while on a large dataset in particular.')\n",
726
  "\n",
 
743
  "\n",
744
  " ###################\n",
745
  "\n",
746
+ " if not os.path.exists('/content/Output-MIDI-Dataset/'+search_settings_string):\n",
747
+ " os.makedirs('/content/Output-MIDI-Dataset/'+search_settings_string)\n",
748
  "\n",
749
  " ###################\n",
750
  "\n",
 
860
  "\n",
861
  " filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]\n",
862
  "\n",
863
+ " filtered_idxs = cp.nonzero(cp.in1d(results, filtered_means))[0]\n",
864
  "\n",
865
+ " all_filtered_means.extend(results[filtered_idxs].tolist())\n",
866
  "\n",
867
  " all_filtered_idxs.extend(filtered_idxs.tolist())\n",
868
  "\n",
 
909
  " #=======================================================\n",
910
  "\n",
911
  " dir_str = str(fn1)\n",
912
+ " copy_path = '/content/Output-MIDI-Dataset/'+search_settings_string+'/'+dir_str\n",
913
  " if not os.path.exists(copy_path):\n",
914
  " os.mkdir(copy_path)\n",
915
  "\n",
master_midi_dataset_gpu_search_and_filter.py CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
6
  Original file is located at
7
  https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Extras/Master_MIDI_Dataset_GPU_Search_and_Filter.ipynb
8
 
9
- # Master MIDI Dataset GPU Search and Filter (ver. 6.0)
10
 
11
  ***
12
 
@@ -165,7 +165,7 @@ print('=' * 70)
165
  print('Loading signatures...')
166
  print('=' * 70)
167
 
168
- signatures_data = cp.array(sigs_matrixes)
169
 
170
  print('Done!')
171
  print('=' * 70)
@@ -192,6 +192,25 @@ print('=' * 70)
192
 
193
  ###########
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  print('Loading MIDI files...')
196
  print('This may take a while on a large dataset in particular.')
197
 
@@ -214,8 +233,8 @@ if filez:
214
 
215
  ###################
216
 
217
- if not os.path.exists('/content/Output-MIDI-Dataset/'+search_matching_type):
218
- os.makedirs('/content/Output-MIDI-Dataset/'+search_matching_type)
219
 
220
  ###################
221
 
@@ -263,7 +282,7 @@ if filez:
263
  for c in cscore:
264
 
265
  pitches = sorted(set([p[4] for p in c if p[3] != 9]))
266
- drums = sorted(set([p[4] for p in c if p[3] == 9]))
267
 
268
  if pitches:
269
  if len(pitches) > 1:
@@ -297,7 +316,10 @@ if filez:
297
  src_signatures = cp.stack(cp.array(src_sigs))
298
 
299
  if not match_drums:
300
- src_signatures = cp.where(src_signatures < drums_offset, src_signatures, epsilon)
 
 
 
301
 
302
  #=======================================================
303
 
@@ -320,9 +342,6 @@ if filez:
320
 
321
  for target_sig in tqdm(src_signatures):
322
 
323
- if not match_drums:
324
- target_sig = cp.where(target_sig < drums_offset, target_sig, epsilon)
325
-
326
  comps_lengths = cp.vstack((cp.repeat(cp.sum(target_sig != 0), signatures_data.shape[0]), cp.sum(signatures_data != 0, axis=1)))
327
  comps_lengths_ratios = cp.divide(cp.min(comps_lengths, axis=0), cp.max(comps_lengths, axis=0))
328
 
@@ -369,9 +388,9 @@ if filez:
369
 
370
  filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]
371
 
372
- filtered_idxs = cp.where(cp.in1d(results, filtered_means))[0]
373
 
374
- all_filtered_means.extend(results[cp.in1d(results, filtered_means)].tolist())
375
 
376
  all_filtered_idxs.extend(filtered_idxs.tolist())
377
 
@@ -418,7 +437,7 @@ if filez:
418
  #=======================================================
419
 
420
  dir_str = str(fn1)
421
- copy_path = '/content/Output-MIDI-Dataset/'+search_matching_type+'/'+dir_str
422
  if not os.path.exists(copy_path):
423
  os.mkdir(copy_path)
424
 
@@ -524,9 +543,9 @@ print('=' * 70)
524
 
525
  number_of_top_matches_MIDIs_to_collect = 30 #@param {type:"slider", min:5, max:50, step:1}
526
  maximum_match_ratio_to_search_for = 1 #@param {type:"slider", min:0, max:1, step:0.001}
527
- match_results_weight = 1 # @param {type:"slider", min:0.1, max:3, step:0.1}
528
- match_lengths_weight = 0.5 # @param {type:"slider", min:0.1, max:3, step:0.1}
529
- match_counts_weight = 0.5 # @param {type:"slider", min:0.1, max:3, step:0.1}
530
  epsilon = 0.5 # @param {type:"slider", min:0.001, max:1, step:0.001}
531
 
532
  print('=' * 70)
@@ -535,6 +554,19 @@ print('=' * 70)
535
 
536
  ###########
537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
538
  print('Loading MIDI files...')
539
  print('This may take a while on a large dataset in particular.')
540
 
@@ -557,8 +589,8 @@ if filez:
557
 
558
  ###################
559
 
560
- if not os.path.exists('/content/Output-MIDI-Dataset/'+search_matching_type):
561
- os.makedirs('/content/Output-MIDI-Dataset/'+search_matching_type)
562
 
563
  ###################
564
 
@@ -674,9 +706,9 @@ if filez:
674
 
675
  filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]
676
 
677
- filtered_idxs = cp.where(cp.in1d(results, filtered_means))[0]
678
 
679
- all_filtered_means.extend(results[cp.in1d(results, filtered_means)].tolist())
680
 
681
  all_filtered_idxs.extend(filtered_idxs.tolist())
682
 
@@ -723,7 +755,7 @@ if filez:
723
  #=======================================================
724
 
725
  dir_str = str(fn1)
726
- copy_path = '/content/Output-MIDI-Dataset/'+search_matching_type+'/'+dir_str
727
  if not os.path.exists(copy_path):
728
  os.mkdir(copy_path)
729
 
 
6
  Original file is located at
7
  https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Extras/Master_MIDI_Dataset_GPU_Search_and_Filter.ipynb
8
 
9
+ # Master MIDI Dataset GPU Search and Filter (ver. 7.0)
10
 
11
  ***
12
 
 
165
  print('Loading signatures...')
166
  print('=' * 70)
167
 
168
+ signatures_data_full = cp.array(sigs_matrixes)
169
 
170
  print('Done!')
171
  print('=' * 70)
 
192
 
193
  ###########
194
 
195
+ search_settings_string = ''
196
+
197
+ if match_drums:
198
+ search_settings_string += 'Chords_Drums'
199
+ else:
200
+ search_settings_string += 'Chords'
201
+
202
+ if search_matching_type == 'Distances':
203
+ search_settings_string += '_O_' + str(distances_norm_order)
204
+
205
+ search_settings_string += '_W_'
206
+ search_settings_string += str(match_results_weight) + '_'
207
+ search_settings_string += str(match_lengths_weight) + '_'
208
+ search_settings_string += str(match_counts_weight)
209
+
210
+ search_settings_string += '_E_' + str(epsilon)
211
+
212
+ ###########
213
+
214
  print('Loading MIDI files...')
215
  print('This may take a while on a large dataset in particular.')
216
 
 
233
 
234
  ###################
235
 
236
+ if not os.path.exists('/content/Output-MIDI-Dataset/'+search_matching_type+'_'+search_settings_string):
237
+ os.makedirs('/content/Output-MIDI-Dataset/'+search_matching_type+'_'+search_settings_string)
238
 
239
  ###################
240
 
 
282
  for c in cscore:
283
 
284
  pitches = sorted(set([p[4] for p in c if p[3] != 9]))
285
+ drums = sorted(set([p[4]+drums_offset for p in c if p[3] == 9]))
286
 
287
  if pitches:
288
  if len(pitches) > 1:
 
316
  src_signatures = cp.stack(cp.array(src_sigs))
317
 
318
  if not match_drums:
319
+ src_signatures = src_signatures[:,:drums_offset]
320
+ signatures_data = signatures_data_full[:,:drums_offset]
321
+ else:
322
+ signatures_data = signatures_data_full
323
 
324
  #=======================================================
325
 
 
342
 
343
  for target_sig in tqdm(src_signatures):
344
 
 
 
 
345
  comps_lengths = cp.vstack((cp.repeat(cp.sum(target_sig != 0), signatures_data.shape[0]), cp.sum(signatures_data != 0, axis=1)))
346
  comps_lengths_ratios = cp.divide(cp.min(comps_lengths, axis=0), cp.max(comps_lengths, axis=0))
347
 
 
388
 
389
  filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]
390
 
391
+ filtered_idxs = cp.nonzero(cp.in1d(results, filtered_means))[0]
392
 
393
+ all_filtered_means.extend(results[filtered_idxs].tolist())
394
 
395
  all_filtered_idxs.extend(filtered_idxs.tolist())
396
 
 
437
  #=======================================================
438
 
439
  dir_str = str(fn1)
440
+ copy_path = '/content/Output-MIDI-Dataset/'+search_matching_type+'_'+search_settings_string+'/'+dir_str
441
  if not os.path.exists(copy_path):
442
  os.mkdir(copy_path)
443
 
 
543
 
544
  number_of_top_matches_MIDIs_to_collect = 30 #@param {type:"slider", min:5, max:50, step:1}
545
  maximum_match_ratio_to_search_for = 1 #@param {type:"slider", min:0, max:1, step:0.001}
546
+ match_results_weight = 2 # @param {type:"slider", min:0.1, max:3, step:0.1}
547
+ match_lengths_weight = 1 # @param {type:"slider", min:0.1, max:3, step:0.1}
548
+ match_counts_weight = 1 # @param {type:"slider", min:0.1, max:3, step:0.1}
549
  epsilon = 0.5 # @param {type:"slider", min:0.001, max:1, step:0.001}
550
 
551
  print('=' * 70)
 
554
 
555
  ###########
556
 
557
+ search_settings_string = ''
558
+
559
+ search_settings_string += str(search_matching_type).replace('-', '_')
560
+
561
+ search_settings_string += '_W_'
562
+ search_settings_string += str(match_results_weight) + '_'
563
+ search_settings_string += str(match_lengths_weight) + '_'
564
+ search_settings_string += str(match_counts_weight)
565
+
566
+ search_settings_string += '_E_' + str(epsilon)
567
+
568
+ ###########
569
+
570
  print('Loading MIDI files...')
571
  print('This may take a while on a large dataset in particular.')
572
 
 
589
 
590
  ###################
591
 
592
+ if not os.path.exists('/content/Output-MIDI-Dataset/'+search_settings_string):
593
+ os.makedirs('/content/Output-MIDI-Dataset/'+search_settings_string)
594
 
595
  ###################
596
 
 
706
 
707
  filtered_means = sorted_means[(sorted_means >= lower_threshold) & (sorted_means <= upper_threshold)][:filter_size]
708
 
709
+ filtered_idxs = cp.nonzero(cp.in1d(results, filtered_means))[0]
710
 
711
+ all_filtered_means.extend(results[filtered_idxs].tolist())
712
 
713
  all_filtered_idxs.extend(filtered_idxs.tolist())
714
 
 
755
  #=======================================================
756
 
757
  dir_str = str(fn1)
758
+ copy_path = '/content/Output-MIDI-Dataset/'+search_settings_string+'/'+dir_str
759
  if not os.path.exists(copy_path):
760
  os.mkdir(copy_path)
761