Tensorflow定义了一个构建所有张量分量乘积的操作

2024-10-02 14:26:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在tensorflow中定义一个运算,计算如下:

enter image description here

x由张量提供。最后,应将操作与已知值进行比较,并应学习参数α、βi和b。在

(我想)所有输入的乘积都会引起麻烦。这是我尝试部署的一个版本,但没有成功。 #输入 X=tf.占位符(tf.float32型,[None,2],name=“X”) Y=tf.占位符(tf.float32型,[None,1],name=“Y”)

# hidden
beta = tf.get_variable("beta", shape=[2], initializer=tf.contrib.layers.xavier_initializer())
powered = tf.pow(X,beta)
productLayer = tf.contrib.keras.layers.multiply(powered) # bad line

# output
w_o = tf.get_variable("w_o", shape=[1], initializer=tf.contrib.layers.xavier_initializer())
b_o = tf.get_variable("bias", shape=[1], initializer=tf.zeros([1]))

output = tf.add(tf.matmul(productLayer,w_o), b_o)
loss = tf.reduce_sum(tf.square(output - Y)) # tf.nn.l2_loss(yhat - Y)

运行gist的完整脚本 https://gist.github.com/anonymous/c17d45b4e997bfccb5275dffa44512d6 将导致错误消息:

File "h2o_test_opti.py", line 13, in productLayer = tf.contrib.keras.layers.multiply(powered) ValueError: A merge layer should be called on a list of inputs.

我认为功能描述tf.contrib.keras公司.图层.倍增适合我的需要。我还试图找到一种简单的方法,如for循环来计算所有传入张量元素的乘积,但没有成功,因为我无法想象以正确的方式访问张量的方法。选择正确的指标不是(?)有可能,因为我不知道当前的步骤,因此正确的张量要处理?在

我想把它作为一个“激活函数”来测试(更确切地说是优化/拟合过程)

请告诉我是否需要更多的信息来帮助解决这个问题。在


Tags: noneoutputgetlayerstfcontribvariablebeta