Ich versuche, meine eigene Kostenfunktion in Tensor-Flow zu schreiben, aber anscheinend kann ich das Tensor-Objekt nicht "schneiden"?Schreiben einer benutzerdefinierten Kostenfunktion in Tensorflow
import tensorflow as tf
import numpy as np
# Establish variables
x = tf.placeholder("float", [None, 3])
W = tf.Variable(tf.zeros([3,6]))
b = tf.Variable(tf.zeros([6]))
# Establish model
y = tf.nn.softmax(tf.matmul(x,W) + b)
# Truth
y_ = tf.placeholder("float", [None,6])
def angle(v1, v2):
return np.arccos(np.sum(v1*v2,axis=1))
def normVec(y):
return np.cross(y[:,[0,2,4]],y[:,[1,3,5]])
angle_distance = -tf.reduce_sum(angle(normVec(y_),normVec(y)))
# This is the example code they give for cross entropy
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
bekomme ich folgende Fehlermeldung: TypeError: Bad slice index [0, 2, 4] of type <type 'list'>
das ist nicht das Problem. Das Problem ist, dass Ihre Variablen nicht initialisiert werden. –