Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我应该如何在tensorflow中将这些输入输入输入到我的回归网络中_Python_Python 2.7_Tensorflow_Regression - Fatal编程技术网

Python 我应该如何在tensorflow中将这些输入输入输入到我的回归网络中

Python 我应该如何在tensorflow中将这些输入输入输入到我的回归网络中,python,python-2.7,tensorflow,regression,Python,Python 2.7,Tensorflow,Regression,我目前正在与tensorflow合作,试图实现一个用于回归的神经网络。回归包括将特定输入映射到输出。我的例子中的输入是采样和帧音频文件,它必须映射到的输出是每个帧应该对应的一组MFCC特性 输入当前是这样存储的 #One audio set [array([[frame],[frame],...,[frame]],dtype=float32)] 而输出目前是这样存储的 [array([[Feature1, Feature2, Feature3, Feature4, Fe

我目前正在与tensorflow合作,试图实现一个用于回归的神经网络。回归包括将特定输入映射到输出。我的例子中的输入是采样和帧音频文件,它必须映射到的输出是每个帧应该对应的一组MFCC特性

输入当前是这样存储的

#One audio set
[array([[frame],[frame],...,[frame]],dtype=float32)]
而输出目前是这样存储的

[array([[Feature1,  Feature2,  Feature3,
         Feature4,  Feature5,  Feature6,
         Feature7,  Feature8,  Feature9,
         Feature10,   Feature11,   Feature12,
         Feature13],....,[...]])]
我目前尝试输入的模型是一个简单的线性模型。 但由于输入或输出数据不是一维数据集,因此我必须以能够处理向量大小的方式提供

# Set model weights
W = tf.Variable(rng.randn(), name="weight")
b = tf.Variable(rng.randn(), name="bias")


# Construct a linear model
pred = tf.add(tf.mul(X, W), b)
经过评估的解决方案

一种解决方案是将输入和输出都展平,并利用每个帧和特征向量长度一致的事实,将权重
W
设置为具有大小[帧长度,特征长度]的矩阵,并将偏差的长度更改为特征长度的长度

这是我的尝试

############################### Training setup ##################################
# Parameters
learning_rate = 0.01
training_epochs = 1000
display_step = 50

# tf Graph Input
X = tf.placeholder(tf.float32, [None])
Y = tf.placeholder(tf.float32, [None])

X_flatten = tf.reshape(X,[1,-1])
Y_flatten = tf.reshape(Y,[1,-1])

# Set model weights
W = tf.Variable(rng.randn(), name="weight")
W = tf.get_variable(name="W", shape=[train_set_data[0].shape[0],train_set_output[0].shape[0]])

b = tf.Variable(rng.randn(), name="bias")
b = tf.get_variable(name="b",shape=[1,train_set_output[0].shape[0]])

# Construct a linear model
pred = tf.add(tf.matmul(X, W), b)

# Mean squared error
cost = tf.nn.softmax(pred)

# Gradient descent
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)

# Initializing the variables
init = tf.initialize_all_variables()

# Launch the graph
with tf.Session() as sess:
    sess.run(init)
    # Fit all training data
    for epoch in range(training_epochs):
        for (x, y) in zip(train_set_data, train_set_output):
            sess.run(optimizer, feed_dict={X: x, Y: y})

        #Display logs per epoch step
        if (epoch+1) % display_step == 0:
            c = sess.run(cost, feed_dict={X: train_set_data, Y:train_set_output})
            print "Epoch:", '%04d' % (epoch+1), "cost=", "{:.9f}".format(c), \
                "W=", sess.run(W), "b=", sess.run(b)

    print "Optimization Finished!"
    training_cost = sess.run(cost, feed_dict={X: train_set_data, Y: train_set_output})
    print "Training cost=", training_cost, "W=", sess.run(W), "b=", sess.run(b), '\n'

    #Graphic display
    plt.plot(train_set_data, train_set_output, 'ro', label='Original data')
    plt.plot(train_set_data, sess.run(W) * train_set_data + sess.run(b), label='Fitted line')
    plt.legend()
    plt.show()
这里的问题是我收到一条错误消息,我不确定我是否理解

Traceback (most recent call last):
  File "tensorflow_datapreprocess_mfcc_extraction_rnn.py", line 177, in <module>
    pred = tf.add(tf.matmul(X, W), b)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py", line 1036, in matmul
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_math_ops.py", line 911, in _mat_mul
    transpose_b=transpose_b, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2156, in create_op
    set_shapes_for_outputs(ret)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1612, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/common_shapes.py", line 81, in matmul_shape
    a_shape = op.inputs[0].get_shape().with_rank(2)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_shape.py", line 625, in with_rank
    raise ValueError("Shape %s must have rank %d" % (self, rank))
ValueError: Shape (?,) must have rank 2
回溯(最近一次呼叫最后一次):
文件“tensorflow_datapreprocess_mfcc_extraction_rnn.py”,第177行,中
pred=tf.add(tf.matmul(X,W),b)
matmul中的文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/math_ops.py”,第1036行
名称=名称)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/gen\u math\u ops.py”,第911行,in\u mat\u mul
转置b=转置b,名称=名称)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/op_def_library.py”,第655行,在apply_op
op_def=op_def)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/framework/ops.py”,第2156行,在create_op中
为输出设置形状(ret)
文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py”,第1612行,用于输出的集合形状
形状=形状函数(op)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/common_shapes.py”,第81行,matmul_形状
a_shape=op.inputs[0]。使用_秩(2)获取_shape()
文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_-shape.py”,第625行,带_-rank
raise VALUERROR(“形状%s必须具有秩%d”%(自身,秩))
ValueError:形状(?)必须具有秩2
你能解释一下为什么我会出现这个错误,或者我提供了一个不同的解决方案。我不太喜欢这个解决方案,因为我正在更改初始输入/输出结构,而不是使用之前预处理创建的结构