2017-02-05 3 views
1

tflearn 모델에 대한 사용자 정의 목적 함수를 생성합니다. 목적 함수는 복잡하고 예측되고 올바른 결과를 반복하고 색인을 기반으로하지 않는 특정 부분을 추가해야합니다. 나는 그것이 텐서 데이터 타입으로 동작하도록하는 방법을 찾을 수 없다.Tflearn 사용자 정의 목표 함수

아래 표준 목록을 사용하여 버전을 코딩했습니다.

errorBuild = 0 
errorCheck = 0 
def CustomLoss(y_pred, y_true): 
    for value, index in enumerate(y_true): 
     if y_true[index] == 0: 
      errorBuild += y_pred[index] 
     else: 
      errorBuild += y_pred[index] - y_true[index] 
      errorCheck += math.abs(errorBuild) 

    return errorCheck 

텐서의 개별 값을 반복하는 방법이없는 것처럼 보입니다. 목적 함수에서 새로운 세션을 만들고 텐서를 평가해야합니까? 사전

+0

이상적으로는 손실을 벡터화 것 (어쩌면 [cumsum] 포함 (https://www.tensorflow.org/api_docs/python/math_ops/scan# : 다음

def my_own_Loss(y_pred, y_true): for value, index in enumerate(y_true): if y_true[index] == 0: errorBuild += y_pred[index] else: errorBuild += y_pred[index] - y_true[index] errorCheck += math.abs(errorBuild) return errorCheck 

과에 전화 cumsum) 및 tf.abs (y_pred [1 :] - y_true)). 그게 가능하지 않다면 [TensorFlow 루핑 구조] (https://www.tensorflow.org/api_docs/python/functional_ops/higher_order_operators)를 살펴볼 것입니다. –

답변

0

당신은/objectives.py 파일 (https://github.com/tflearn/tflearn/blob/master/tflearn/objectives.py)을 tflearn하는 새로운 손실 함수를 추가 할 수있는 도움을

감사합니다. 그것을 사용하기 위해서는 회귀 레이어에서 그 이름을 호출하면됩니다.

net = tflearn.regression(net, optimizer='momentum', 
         loss='my_own_Loss', 
         learning_rate=0.1)