slaypni / fastdtw

A Python implementation of FastDTW
MIT License
785 stars 122 forks source link

fastdtw doesn't work in lambda... #11

Closed wesky93 closed 6 years ago

wesky93 commented 7 years ago

I have two code. one is use default dist, another is use Euclidean func.. I test two code in my MacBook. and it work! but in AWS lambda it doesn't work.. but I don't know why.. because Euclidean func is work but default doesn't work.. this is AWS lambda error..

>>> from fastdtw import fastdtw
>>> import numpy as np
>>> np.zeros((3,5))
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> a = np.zeros((3,5))
>>> b = np.zeros((3,5))
>>> fastdtw(a,b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fastdtw.py", line 65, in fastdtw
    return __fastdtw(x, y, radius, dist)
  File "fastdtw.py", line 85, in __fastdtw
    __fastdtw(x_shrinked, y_shrinked, radius=radius, dist=dist)
  File "fastdtw.py", line 80, in __fastdtw
    return dtw(x, y, dist=dist)
  File "fastdtw.py", line 128, in dtw
    (D[i-1, j-1][0]+dt, i-1, j-1), key=lambda a: a[0])
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

but same code In my Mackbook.. it work!

>>> import numpy as np
>>> from fastdtw import fastdtw
>>> a = np.zeros((4,5))
>>> b = np.zeros((4,5))
>>> fastdtw(a,b)
Out[6]: (0.0, [(0, 0), (1, 1), (2, 2), (3, 3)])
>>> dist,path = fastdtw(a,b)
>>> dist
Out[8]: 0.0
>>> path
Out[9]: [(0, 0), (1, 1), (2, 2), (3, 3)]
wesky93 commented 7 years ago

oh and AWS lambda OS is

The underlying AWS Lambda execution environment is based on the following:

Public Amazon Linux AMI version (AMI name: amzn-ami-hvm-2016.03.3.x86_64-gp2):
For information about using an AMI, see Amazon Machine Images (AMI) in the Amazon EC2 User Guide for Linux Instances.
Linux kernel version – 4.4.35-33.55.amzn1.x86_64

check this

Apathyman commented 7 years ago

Where did you compile your dependencies?

Gargosio commented 6 years ago

hey.Trying to use fastdtw with librosa but getting the error below.Kindly assist import librosa from numpy.linalg import norm from fastdtw import fastdtw

Loading audio files

y1, sr1 = librosa.load('coolBack.wav') y2, sr2 = librosa.load('nelly.wav') mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC value mfcc2 = librosa.feature.mfcc(y2, sr2) #Computing MFCC value dist, cost, acc_cost, path = fastdtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1)) print('Normalized distance between the two sounds:', dist) #Comparison of the two using DTW

ValueError Traceback (most recent call last)

in () 8 mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC value 9 mfcc2 = librosa.feature.mfcc(y2, sr2) #Computing MFCC value ---> 10 dist, cost, acc_cost, path = fastdtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1)) 11 print('Normalized distance between the two sounds:', dist) #Comparison of the two using DTW ValueError: not enough values to unpack (expected 4, got 2)
wesky93 commented 6 years ago

@Apathyman oh. I solved this problem by compiling in the same environment.