I
I
Ivan Vishnevsky2018-08-15 16:57:45
Python
Ivan Vishnevsky, 2018-08-15 16:57:45

How to defeat you must feed a value for placeholder tensor (TensorFlow)?

Is there a code that says something like this

#learning parameters
    learningRate = 0.01
    trainingIteration = 30
    batch_size = 100

    x = tf.placeholder(tf.float32, [batch_size, 36], name='x')
    W = tf.Variable(tf.zeros([36, batch_size]))
    b = tf.Variable([0.1], name='bias')
    y = tf.placeholder(tf.float32, [batch_size, 1], name='y')

    with tf.name_scope('linearModel') as scope:
        linear_model = tf.identity(tf.matmul(x, W) + b)
    # ...
    # ...
    # ...
    with tf.Session() as sess:
        init = tf.global_variables_initializer()
        sess.run(init)

        for iteration in range(trainingIteration):
            avg_cost = 0.
            batch_list = []
            for i in range(batch_size):
                rand = randint(0, len(dataset))
                batch_list.append(dataset[rand])
            dataDict = dataset[rand]
            datasetX = [*map(lambda data: data['inData'], batch_list)]
            datasetY = [*map(lambda data: [data['outData']], batch_list)]

            sess.run(optimizer, feed_dict = {x: datasetX, y: datasetY})

            if iteration % 10 == 0:
                print(sess.run(x))

In fact, in an iteration, I take 100 random values ​​​​from the dataset, in x we ​​have 36 values, in y - one. They are definitely of the Python float type. But this python code swears, says: "You must feed a value for placeholder tensor 'x' with dtype float and shape [100, 36]"
Moreover, if you change the stuffing of elements into the supplied array to
for i in range(batch_size -1):
        rand = randint(0, len(dataset))
        batch_list.append(dataset[rand])

, then the error is: cannot feed value of shape (99, 36) for Tensor 'x:0' which has shape '(100, 36)'
Where to dig? I suppose the error should be simple, the first time I encounter, in fact, with python and ML.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question