Filler feed parameters in tensor flow

I try to connect to the tensor stream, configure the network and then feed data to it. For some reason, I am ending the error message ValueError: setting an array element with a sequence. I made a minimal example of what I'm trying to do:

import tensorflow as tf
K = 10

lchild = tf.placeholder(tf.float32, shape=(K))
rchild = tf.placeholder(tf.float32, shape=(K))
parent = tf.nn.tanh(tf.add(lchild, rchild))

input = [ tf.Variable(tf.random_normal([K])),
          tf.Variable(tf.random_normal([K])) ]

with tf.Session() as sess :
    print(sess.run([parent], feed_dict={ lchild: input[0], rchild: input[1] }))

Basically, I set up a network with place owners and an input attachment sequence that I want to learn, and then I try to start the network by supplying input attachments to it. From what I can tell by searching for the error message, there may be something wrong with mine feed_dict, but I do not see any obvious inconsistencies, for example. Dimension.

So what did I miss, or how did I get this all the way back?

EDIT: , , , . , : ?

+4
1

numpy.

, tf.Variable(tf.random_normal([K])) np.random.randn(K), .

EDIT ( ):

, . :

lchild = tf.placeholder(tf.float32, shape=(K))
rchild = tf.placeholder(tf.float32, shape=(K))
parent = tf.nn.tanh(tf.add(lchild, rchild))
loss = <some loss that depends on the parent tensor or lchild/rchild>
# Compute gradients with respect to the input variables
grads = tf.gradients(loss, [lchild, rchild])

inputs = [np.random.randn(K), np.random.randn(K)]
for i in range(<number of iterations>):
    np_grads = sess.run(grads, feed_dict={lchild:inputs[0], rchild:inputs[1])
    inputs[0] -= 0.1 * np_grads[0]
    inputs[1] -= 0.1 * np_grads[1]

. , numpy ( , GPU).

, (, ). tenorflow :

lchild = tf.Variable(tf.random_normal([K])
rchild = tf.Variable(tf.random_normal([K])
parent = tf.nn.tanh(tf.add(lchild, rchild))
loss = <some loss that depends on the parent tensor or lchild/rchild>
train_op = tf.train.GradientDescentOptimizer(loss).minimize(0.1)

for i in range(<number of iterations>):
    sess.run(train_op)

# Retrieve the weights back to numpy:
np_lchild = sess.run(lchild)
+7

Source: https://habr.com/ru/post/1620493/


All Articles