张量'对象不可迭代

时间:2018-01-09 03:41:31

标签: python tensorflow machine-learning linear-regression

我有以下消息' Tensor'对象不可迭代。"在尝试运行我的代码时,有人能告诉我我的错误在哪里吗? 所有问题都开始了,因为我需要规范化我正在提供的数据。因此问题来自我的代码的这一部分:

if(isset($_POST['rr_number']) && isset($_POST['rr_number']) != "") {

    $rr_number = clean(unhex(base64_decode(base64_decode(stripslashes(trim(mysqli_real_escape_string($new_conn, $_POST['rr_number'])))))));

    $query = mysqli_query($new_conn, "SELECT * FROM receiving_reports WHERE rr_number = '$rr_number'");

    $response = array();
    if(mysqli_num_rows($query) > 0) {
        while($row = mysqli_fetch_assoc($query)) {
            $response = $row;
        }
    } else {
        $response['status'] = 200;
        $response['message'] = "Data not found!";
    }

    echo json_encode($response);
} else {

    $response['status'] = 200;
    $response['message'] = "Invalid Request!";
}

以下是我的全部代码:

    for epoch in range(training_epochs):
    avg_cost = 0.
    total_batch = int(total_len / batch_size)
    # Loop over all batches
    for i in range(total_batch):
        batch_x = tf.train.batch(X_train_norm, batch_size)
        batch_y = tf.train.batch(Y_train, batch_size)
        # Run optimization op (backprop) and cost op (to get loss value)
        _, c, p = sess.run([optimizer, cost, pred], feed_dict={x: batch_x, y: batch_y})

        # Compute average loss
        avg_cost += c / total_batch

    # sample prediction
    label_value = batch_y
    estimate = p
    err = label_value - estimate
    print("num batch:", total_batch)

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我发现如果我把结果放在一个会话中就会给我我需要的东西

batch_x_norm = tf.Session().run(tf.nn.l2_normalize(batch_x, 0, epsilon=1e-12))