2017-09-09 4 views
1

I했습니다 같은 간단한 모델 :tensorflow의 손실을 계산하는 방법은 무엇입니까?

n_input = 14 
n_out = 1 

weights = { 
    'out': tf.Variable(tf.random_normal([n_input, n_out])) 
} 
biases = { 
    'out': tf.Variable(tf.random_normal([n_out])) 
} 
def perceptron(input_tensor, weights, biases): 
    out_layer_multiplication = tf.matmul(input_tensor, weights['out']) 
    out_layer_addition = out_layer_multiplication + biases['out'] 
    return out_layer_addition 

input_tensor = rows 
model = perceptron 

"행"치수 (N, 14) 및 "밖으로"치수는 (N)이다 "밖으로", "행"로 모델을 실행의 결과는 "input_tensor"로 지정하십시오.

그리고 tensorflow의 손실을 계산하고 싶습니다. 계산의 Algorythm은 다음과 같습니다.

ls = 0 
for i in range(len(out)-1): 
    if out[i] < out[i+1]: 
     ls += 1 

"ls"는 모델 손실입니다. 어떻게 그것을 텐서 플로우 표기법으로 계산할 수 있습니까?

답변

1

당신은 같은 것을 할 수 있습니다 : 실제로

l = out.get_shape()[0] 
a = out[0:l-1] 
b = out[1:l] 
c = tf.where(a<b, tf.ones_like(a), tf.zeros_like(a)) 
return tf.reduce_sum(c) 

, aout[i]를 포함하고 bout[i+1]가 포함되어 있습니다. out[i]<out[i+1] 때마다 c에 1이 있습니다. 그래서 그들을 합하면 매번 +1이되는 것과 같습니다.

관련 문제