python - How should i feed this input into my regression network in tensorflow -
i working tensorflow, trying implement neural network regression purposes. regression consist of mapping input output. input in case samples , framed audio files, , output has mapped set of mfcc features each frame should correspond to.
the input stored this.
#one audio set [array([[frame],[frame],...,[frame]],dtype=float32)]
and output stored this
[array([[feature1, feature2, feature3, feature4, feature5, feature6, feature7, feature8, feature9, feature10, feature11, feature12, feature13],....,[...]])]
the model trying input simple linear model. since input or output data isn't 1 dimensional dataset, have provide in way such capable of handling vector sizes.
# set model weights w = tf.variable(rng.randn(), name="weight") b = tf.variable(rng.randn(), name="bias") # construct linear model pred = tf.add(tf.mul(x, w), b)
evaluated solutions
one solution flatten both input, , output , make use of fact each frame , feature vector consistent in length, , make weight w
matrix has size [frame_length, feature_length], , change length of bias length of feature_length.
here attempt of doing this.
############################### 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 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 variables init = tf.initialize_all_variables() # launch graph tf.session() sess: sess.run(init) # fit training data epoch in range(training_epochs): (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()
problem here getting error message not sure understand..
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
could explain why getting error, or different solution 1 i've provided. not fond of solution, changing initial input/output structure, rather using 1 created prior preprocessing.
Comments
Post a Comment