循環平均二乗誤差損失を計算するために、TensorFlow にカスタム損失関数を実装しようとしています。
両方のベクトル (1D) である y と yPredict の真の値と予測値の差をとっています。j の範囲が -20 から 20 の別の変数 2*j*pi を追加しています。ただし、このコード行の計算に問題があるようです。
err_matrix = tf.Variable(np.zeros((np.shape(yPredict)[0], np.shape(yPredict)[1], k.shape[0])))
エラーメッセージは次のとおりです。
ValueError: slice index 1 of dimension 1 out of bounds. for 'strided_slice' (op: 'StridedSlice') with input shapes: [100,1,41], [2], [2], [2] and with computed input tensors: input[1] = <0 1>, input[2] = <0 2>, input[3] = <1 1>.
これは完全な関数と関数呼び出し、およびオプティマイザーへのリンク方法です。
関数:
def wmse(yPredict,y):
k = tf.constant(np.array(range(-20, 21)))
err_matrix = tf.Variable(np.zeros((np.shape(yPredict)[0], np.shape(yPredict)[1], k.shape[0])))
for j in range(1, k.shape[0]):
err_matrix[:, j] += tf.subtract(tf.subtract(yPredict,y), tf.constant(2*j*tf.constant(np.pi)))
errs = tf.reduce_min(err_matrix, axis=1)
std_CNN_errors = tf.sqrt(tf.reduce_mean(tf.square(errs)))
return std_CNN_errors
関数呼び出し:
cost_function = wmse(network_outputs, outputs)
optimizer = tf.train.AdamOptimizer(learning_rate=1e-4).minimize(cost_function, var_list=tf.trainable_variables())
誰かがこれで私を助けてくれますか? ありがとう!