【发布时间】:2016-06-03 16:35:08
【问题描述】:
我目前正在使用 Tensorflow 开发四元数神经网络(我想使用 GPU)。 TensorFlow 不支持四元数,但您可以将其表示为 4x4 实数矩阵,因此可以在 TensorFlow 中构建这样的神经网络。
是否有一种简单的方法可以添加自定义操作或对张量进行自定义操作?
例如,我可以这样写:
output_activation = tf.nn.softmax(tf.matmul(hidden_activation, Weight_to_ouput))
...这很酷!您所要做的就是添加一个损失函数,然后进行反向传播。但是,我想用四元数做同样的事情,例如:
output_activation = mySigmoid(myFunction(hidden_activation, Weight_to_output))
但是,我需要将四元数转换为张量和从张量转换以优化 GPU 计算。所以我需要创建一个函数来获取一些张量作为参数并返回转换后的张量。
我看过py_func,但您似乎无法返回张量。
我尝试了以下方法,但失败了:
def layerActivation(inputTensor,WeightTensor):
newTensor = tf.matmul(inputTensor,WeightTensor)
return newTensor
...在main():
x = placeholder ...
W_to_hidden = tf.Variable
test = tf.py_func(layerActivation, [x,_W_to_hidden], [tf.float32])
with tf.Session() as sess:
tf.initialize_all_variables().run()
king_return = sess.run(test, feed_dict={x: qtrain})
错误:未实现:不支持的对象类型张量
理想情况下,我可以在 TensorFlow 的标准反向传播算法中使用这个 output_activation,但我不知道这是否可能。
【问题讨论】:
标签: python neural-network tensorflow