将ndarrays传递给dict返回-“您必须提供占位符张量的值”

时间:2019-06-05 15:28:18

标签: python tensorflow deep-learning

我是tensorflow的新手。我想将训练数据(ReleaseXs分别是Ys[85,31951,9]的3d数组)传递给[85,31951,1]块内的占位符输入和目标。

tf.session中的85个样本,31951个时间戳和9个功能。

我尝试在Feed dict中传递X只是为了查看我的输入数据维度是否存在任何问题。错误仍然存​​在。

  

“您必须使用dtype输入占位符张量'占位符'的值   漂浮和形状[85,31951,9]”。

如果我将第一维(样本)从np.random.random((85, 31951, 9))转换为85,则代码会运行,但是我会在None中遇到Unknown shape错误。如果需要,我可以发布更多代码。任何帮助表示赞赏。

tf.gather

我用于输入输入和目标的占位符是:

with tf.Session(graph=lstm_graph) as sess: 
    tf.global_variables_initializer().run()

    x_train_IV_nd, x_train_DV_nd = prep_data()
    print(np.shape(x_train_IV_nd))
    print(type(x_train_IV_nd))
    # print(x_train_IV_nd.dtype)
    learning_rates_to_use = [
        config.init_learning_rate * (
            config.learning_rate_decay ** max(float(i + 1 - config.init_epoch), 0.0)
        ) for i in range(config.max_epoch)]

    for epoch_step in range(config.max_epoch):
        current_lr = learning_rates_to_use[epoch_step]
        train_loss, _ = sess.run([loss, minimize], feed_dict={inputs: np.random.random((85, 31951, 9)), targets: np.random.random((85, 31951, 1))})

网络设置:

inputs = tf.placeholder(tf.float32, shape = (85,31951,9))  
targets = tf.placeholder(tf.float32, shape = (85,31951,1)) 

错误:

class RNNConfig():
    input_size=9 
    num_steps=31951   
    num_units = 128  
    lstm_size=9
    num_layers=9
    keep_prob=0.8
    batch_size = 85
    init_learning_rate = 0.001
    learning_rate_decay = 0.99
    init_epoch = 5
    max_epoch = 50

1 个答案:

答案 0 :(得分:0)

仅当占位符张量未收到其值时才会出现此错误。

我运行了一个伪代码,它可以正常工作。

import numpy as np
import tensorflow as tf

inputs = tf.placeholder(tf.float32, shape = (85,31951,9))  
targets = tf.placeholder(tf.float32, shape = (85,31951,1)) 

def out(inputs, targets):
    return inputs, targets

loss = out(inputs, targets)

with tf.Session() as sess: 
    tf.global_variables_initializer().run()
    output = sess.run([loss], feed_dict={inputs: np.random.random((85, 31951, 9)), targets: np.random.random((85, 31951, 1))})
    print("Printing the inputs to the tensors")
    print(output)

请签入您的代码或共享您的代码以进一步调试问题。