今kerasを用いて自作評価関数を作成しているのですが以下に示すようなエラーが解決しません.
評価関数の内容としてはある座標の(x,y)を予測し正解値との距離が0.3以下であればカウントを行い正答率を評価するというものです.
エラーを解決するにはどのようなことを行えばよいでしょうか?
python
1#評価関数(距離の正答率) 2def loss_a(y_true, y_pred): 3 test = [] 4 norm = K.sqrt(K.sum(K.square(y_pred - y_true), axis=-1)) 5 6 if norm<=0.3: 7 label=0 8 test.append(label) 9 10 return test.count(0) 11 12 13# model compile 14 15model.compile(loss=euclidean_distance_loss, 16 optimizer=opt, 17 metrics=[loss_a])
error
1開始時刻: 1579109193.9544458 2--------------------------------------------------------------------------- 3OperatorNotAllowedInGraphError Traceback (most recent call last) 4<ipython-input-5-02ac6fd32348> in <module>() 5 184 model.compile(loss=euclidean_distance_loss, 6 185 optimizer=opt, 7--> 186 metrics=[loss_a]) 8 187 9 188 #CSVに各エポックの学習結果の保存 10 1113 frames 12/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py in _disallow_in_graph_mode(self, task) 13 521 raise errors.OperatorNotAllowedInGraphError( 14 522 "{} is not allowed in Graph execution. Use Eager execution or decorate" 15--> 523 " this function with @tf.function.".format(task)) 16 524 17 525 def _disallow_bool_casting(self): 18 19OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。