में एक कस्टम लागत फ़ंक्शन लिखना मैं टेंसर प्रवाह में अपना खुद का लागत फ़ंक्शन लिखने की कोशिश कर रहा हूं, हालांकि जाहिर है कि मैं टेंसर ऑब्जेक्ट को 'स्लाइस' नहीं कर सकता हूं?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))
मैं निम्नलिखित त्रुटि मिलती है: TypeError: Bad slice index [0, 2, 4] of type <type 'list'>
यह समस्या नहीं है। समस्या यह है कि आपके चर प्रारंभ नहीं किए गए हैं। –