2017-05-25 72 views
0

我想從函數返回7個值並稍後打印這些值。 但是當我將它們打印出來時,我總是得到第一個值的七個副本。Tensorflow/Python:返回第一個元素的副本的函數元組

雖然我似乎無法理解我做錯了什麼。

代碼的作用是比較元素的張量(數組),並檢查在某些閾值下的元素的百分比。

def accuracy(): 
    n=7850 
    m = 100.0 
    difference = tf.abs(tf.subtract(prediction,(labels_tf))) 
    one = tf.reduce_sum(tf.cast(tf.less(difference,[1]),dtype=tf.int32)) 
    one = tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 

    two = tf.reduce_sum(tf.cast(tf.less(difference,[2]),dtype=tf.int32)) 
    two = tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 

    three =tf.reduce_sum(tf.cast(tf.less(difference,[3]),dtype=tf.int32)) 
    three =tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 

    four= tf.reduce_sum(tf.cast(tf.less(difference,[4]),dtype=tf.int32)) 
    four= tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 

    five= tf.reduce_sum(tf.cast(tf.less(difference,[5]),dtype=tf.int32)) 
    five= tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 

    ten = tf.reduce_sum(tf.cast(tf.less(difference,[10]),dtype=tf.int32)) 
    ten = tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 

    fifteen =tf.reduce_sum(tf.cast(tf.less(difference,[15]),dtype=tf.int32)) 
    fifteen = tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 



    return (one, two, three, four, five, ten, fifteen) 

a1,a2,a3,a4,a5,a10,a15 = accuracy() 

回答

0

你傳遞one到每個組操作的第二行即

fifteen = tf.multiply(tf.divide(tf.cast(one,dtype=tf.float32),n),m) 
             ^^ 
+0

uggh。我應該得到這個子彈。謝謝! – Simmeman

相關問題