"minor": [1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0] } MODE['major'] = utils.rotate(MODE['major'], key_ind) MODE['minor'] = utils.rotate(MODE['minor'], key_ind) r_co_major = pearsonr(chroma_vector, MODE["major"]) r_co_minor = pearsonr(chroma_vector, MODE["minor"]) # print(r_co_major[0]) # print(r_co_minor[0]) mode = '' Cmajor_annoatation = (key_ind + 3) % 12 if (r_co_major[0] > r_co_minor[0]): mode = Cmajor_annoatation else: mode = Cmajor_annoatation + 12 mode = utils.lerch_to_str(mode) # print('mode', mode) if DB == 'GTZAN': pred[gen].append(mode) else: pred.append( '?') # you may ignore this when starting with GTZAN dataset # print(pred[gen]) print("***** Q2 *****") if DB == 'GTZAN': label_list, pred_list = list(), list() print("Genre \taccuracy") for g in GENRE: # TODO: Calculate the accuracy for each genre
tonic_note = tonic max_r = correlation_major else: if correlation_minor > max_r: mode = "minor" tonic_note = tonic max_r = correlation_minor note = Tonic_keys[tonic_note] + " " + mode pred = utils.str_to_lerch(note) predictions.append(pred) except Exception as e: print(e) predictions.append(0) #break score = 0 for i in range(len(labels)): score = score + weighted_score(utils.lerch_to_str(labels[i]), utils.lerch_to_str(predictions[i])) weighted_accuracy = score / len(labels) accuracy = accuracy_score(labels, predictions, normalize=True, sample_weight=None) fout = open('output/Task3_2.txt', 'a') fout.write("***** Task 3: local key detection *****\n") fout.write("A-MAPS Overall Accuracy:\t{:.2f}%\n".format(accuracy * 100)) fout.write("A-MAPS Overall Weighted Accuracy:\t{:.2f}%\n".format( weighted_accuracy * 100)) fout.close()
"cMinor": [1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0]} mode['cMajor'] = utils.rotate(mode['cMajor'], key_ind) mode['cMinor'] = utils.rotate(mode['cMinor'], key_ind) cMajorCoefficient = pearsonr(chroma_vector, mode['cMajor']) cMinorCoefficient = pearsonr(chroma_vector, mode['cMinor']) mode = '' a = (key_ind+3)%12 if (cMajorCoefficient[0] > cMinorCoefficient[0]): modePred = a else: modePred = a+12 modePred = utils.lerch_to_str(modePred) if DB == 'GTZAN': pred[gen].append(modePred) else: pred.append('?') # you may ignore this when starting with GTZAN dataset # print(pred[gen]) print("***** Q2 *****") if DB == 'GTZAN': label_list, pred_list = list(), list() print("Genre \taccuracy") for g in GENRE: # TODO: Calculate the accuracy for each genre # Hint: Use label[g] and pred[g] correct = 0
chroma_vector.pop(0) chroma_vector.append(temp) maxRMajor = np.where(coffiListsMaj == np.amax(coffiListsMaj)) maxRMinor = np.where(coffiListsMin == np.amax(coffiListsMin)) maxRMajor = maxRMajor[0][0] maxRMinor = maxRMinor[0][0] if coffiListsMaj[maxRMajor] > coffiListsMin[maxRMinor]: key_ind = (maxRMajor + 3) % 12 else: key_ind = (maxRMinor + 15) % 24 # print('key_ind: {}\n'.format(key_ind)) modePred = utils.lerch_to_str(key_ind) if DB == 'GTZAN': pred[gen].append(modePred) else: pred.append( '?') # you may ignore this when starting with GTZAN dataset coffiListsMaj = [] coffiListsMin = [] print("***** Q4 *****") if DB == 'GTZAN': label_list, pred_list = list(), list() print("Genre \taccuracy") for g in GENRE: