From 7268ce0a787a97b89cdbd55cb56e0ca1b7a7b79c Mon Sep 17 00:00:00 2001 From: Anurag Kumar Date: Tue, 5 Dec 2017 10:08:23 +0530 Subject: [PATCH 1/2] [comments-only] Update fingerprint.py type at line #97. FINGERPRINT_REDUCTION is actually being used to slice generated hash from 0th to FINGERPRINT_REDUCTION(th) position, updated the comment accordingly --- dejavu/fingerprint.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dejavu/fingerprint.py b/dejavu/fingerprint.py index 4db321b..2617aaf 100755 --- a/dejavu/fingerprint.py +++ b/dejavu/fingerprint.py @@ -56,9 +56,9 @@ MAX_HASH_TIME_DELTA = 200 PEAK_SORT = True ###################################################################### -# Number of bits to throw away from the front of the SHA1 hash in the -# fingerprint calculation. The more you throw away, the less storage, but -# potentially higher collisions and misclassifications when identifying songs. +# Number of bits to grab from the front of the SHA1 hash in the +# fingerprint calculation. The more you grab, the more memory storage, +# with potentially lesser collisions of matches. FINGERPRINT_REDUCTION = 20 def fingerprint(channel_samples, Fs=DEFAULT_FS, @@ -94,7 +94,7 @@ def get_2D_peaks(arr2D, plot=False, amp_min=DEFAULT_AMP_MIN): struct = generate_binary_structure(2, 1) neighborhood = iterate_structure(struct, PEAK_NEIGHBORHOOD_SIZE) - # find local maxima using our fliter shape + # find local maxima using our filter shape local_max = maximum_filter(arr2D, footprint=neighborhood) == arr2D background = (arr2D == 0) eroded_background = binary_erosion(background, structure=neighborhood, From 1204f77bd15378e201ab820cf323107e1815403b Mon Sep 17 00:00:00 2001 From: Anurag Kumar Date: Wed, 6 Dec 2017 10:02:33 +0530 Subject: [PATCH 2/2] Updated fingerprint.py Reduced the amount of iterations that will execute in the edited lines, using filter with python3 will reduce iteration a lot as it defines a generator rather than a list. --- dejavu/fingerprint.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dejavu/fingerprint.py b/dejavu/fingerprint.py index 2617aaf..1455900 100755 --- a/dejavu/fingerprint.py +++ b/dejavu/fingerprint.py @@ -110,12 +110,14 @@ def get_2D_peaks(arr2D, plot=False, amp_min=DEFAULT_AMP_MIN): # filter peaks amps = amps.flatten() peaks = zip(i, j, amps) - peaks_filtered = [x for x in peaks if x[2] > amp_min] # freq, time, amp - + peaks_filtered = filter(lambda x: x[2]>amp_min, peaks) # freq, time, amp # get indices for frequency and time - frequency_idx = [x[1] for x in peaks_filtered] - time_idx = [x[0] for x in peaks_filtered] - + frequency_idx = [] + time_idx = [] + for x in peaks_filtered: + frequency_idx.append(x[1]) + time_idx.append(x[0]) + if plot: # scatter of the peaks fig, ax = plt.subplots()