lundi 28 mai 2018

neural network from [., 3] to [., 2] prediction

I have 3 incoming blue-tooth signals and try to predict my x, y coordinates based on these signal strength. I've build a network but can't resolve changing it to a 2 output network.

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

My network looks like this:

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.network, 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]

Aucun commentaire:

Enregistrer un commentaire