我在定义的自定义指标中遇到了一些问题,如下所示:
@tf.function
def nossa_metrica(y_true, y_pred):
truepotventolow = K.cast(K.less_equal(y_true[:,0], 4000), 'int8')
predpotventolow = K.cast(K.less_equal(y_pred[:,0], 4000), 'int8')
potventolow = sum(truepotventolow*predpotventolow)
truepotventomed = K.cast(K.greater(y_true[:,0], 4000) & K.less_equal(y_true[:,0], 8500), 'int8')
predpotventomed = K.cast(K.greater(y_pred[:,0], 4000) & K.less_equal(y_pred[:,0], 8500), 'int8')
potventomed = sum(truepotventomed*predpotventomed)
truepotventohigh = K.cast(K.greater(y_true[:,0], 8500), 'int8')
predpotventohigh = K.cast(K.greater(y_pred[:,0], 8500), 'int8')
potventohigh = sum(truepotventohigh*predpotventohigh)
truedesvpadlow = K.cast(K.less_equal(y_true[:,1], 1150), 'int8')
preddesvpadlow = K.cast(K.less_equal(y_pred[:,1], 1150), 'int8')
desvpadlow = sum(truedesvpadlow*preddesvpadlow)
truedesvpadmed = K.cast(K.greater(y_true[:,1], 1150) & K.less_equal(y_true[:,1], 2300), 'int8')
preddesvpadmed = K.cast(K.greater(y_pred[:,1], 1150) & K.less_equal(y_pred[:,1], 2300), 'int8')
desvpadmed = sum(truedesvpadmed*preddesvpadmed)
truedesvpadhigh = K.cast(K.greater(y_true[:,1], 2300), 'int8')
preddesvpadhigh = K.cast(K.greater(y_pred[:,1], 2300), 'int8')
desvpadhigh = sum(truedesvpadhigh*preddesvpadhigh)
truewlslow = K.cast(K.less_equal(y_true[:,2], 0.075), 'int8')
predwlslow = K.cast(K.less_equal(y_pred[:,2], 0.075), 'int8')
wlslow = sum(truewlslow*predwlslow)
truewlshigh = K.cast(K.greater(y_true[:,2], 0.075), 'int8')
predwlshigh = K.cast(K.greater(y_pred[:,2], 0.075), 'int8')
wlshigh = sum(truewlshigh*predwlshigh)
return (potventolow+potventomed+potventohigh+desvpadlow+desvpadmed+desvpadhigh+wlslow+wlshigh)/((batch_size+max(1,np.int(0.2*batch_size)))*Yclasses)
在model.compile
中,出现以下错误:
OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed: AutoGraph did not convert this function. Try decorating it directly with @tf.function.
有什么主意我该如何解决?