神经网络从[。,3]到[。,2]预测

时间:2018-05-28 12:16:08

标签: tensorflow neural-network prediction

我有3个输入的蓝牙信号,并尝试根据这些信号强度预测我的x,y坐标。我已经建立了一个网络,但无法解决将其更改为2输出网络的问题。

#my input:
[[50,35,21],[40,36,25],...[20,5,-5]]
#my labels:
[[10,2],    [10,2],    ...[4,0]  ]

我的网络如下:

class Network:
    def __init__(self, input, labels):
        self.input = input
        self.labels = labels
        self.num_input = input.shape[1]
        self.num_output = labels.shape[1]
        self.X = tf.placeholder("float", [None, self.num_input])
        self.Y = tf.placeholder("float", [None, self.num_output])

        self.layer_1 = tf.add(tf.matmul(self.X, w1 = [self.num_input, 256], b1 = [256])
        ...
        self.lastLayer = tf.matmul(self.layer_5, wLast = [128, self.num_output], bLast = [num_output])

        self.loss_op = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=self.lastLayer, labels=self.Y))
        self.optimizer = tf.train.AdamOptimizer(learning_rate=self.learning_rate)
        self.train_op = self.optimizer.minimize(self.loss_op)


    def train(self):
        with tf.Session() as sess:
            sess.run(tf.global_variables_initializer())
            for step in range(1, 500):
                batch_x, batch_y = self.random_batch(self.numpy_input, self.numpy_labels, self.batch_size)
                sess.run(self.train_op, feed_dict={self.X: batch_x, self.Y: batch_y})

    def predict(self, test_input, test_labels):
       #how do I write this
       prediction = XXX       

       for i in range(test_labels):
          print("Label: ", test_labels[i], " was predicted as: ", prediction[i])

0 个答案:

没有答案