1

我是一名博士生,但不是深度学习或 Python 方面的专家,如果我的问题微不足道,请见谅。我想要做的是使用快速 dtw ( https://pypi.org/project/fastdtw/ ) 作为我的 TensorFlow 模型的损失函数。(RNN) 定义函数后:

def dtw_distance (x,y):
  distance, path=fastdtw(x, y)
  return distance

我正在尝试用它作为损失函数来编译我的模型:

from keras.callbacks import EarlyStopping, ModelCheckpoint

earlystopper = EarlyStopping(patience=10, verbose=1,monitor='loss')

checkpointer = ModelCheckpoint('model-dsbowl2018-1.h5', verbose=1, save_best_only=True,monitor='loss')

results = model.fit(train_av, train_ap, validation_split=0.1, batch_size=10, epochs=100,callbacks=[earlystopper, checkpointer])

我有以下错误消息:TypeError:在用户代码中:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:806 train_function  *
    return step_function(self, iterator)
<ipython-input-45-aacde9207c50>:2 dtw_distance  *
    distance, path=fastdtw(x, y)
fastdtw/_fastdtw.pyx:78 fastdtw._fastdtw.fastdtw  **
    
fastdtw/_fastdtw.pyx:222 fastdtw._fastdtw.__prep_inputs
    
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py:138 asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)

TypeError: __array__() takes 1 positional argument but 2 were given

即使在我的函数中添加一个 self 参数,同样的错误仍然存​​在。我在这里想念什么?

谢谢

4

0 回答 0