当我尝试为keras创建自定义度量时(联合交集(时,我有错误。我想找到有关两个图像(张量(的联合的交集
def IoU(y_true,y_pred):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
#assert len(y_true_f) != len(y_pred_f)
y_true_f = y_true_f.eval(session = K.get_session())
y_pred_f = y_pred_f.eval(session = K.get_session())
union1 = [i for i,j in zip(y_true_f,y_pred_f) if i != j]
union2 = [j for i,j in zip(y_true_f,y_pred_f) if i != j]
intersection = [i for i,j in zip(y_true_f,y_pred_f) if i == j]
unionAll = union1 + union2 + intersection
return (np.sum(intersection) + smooth) / float(np.sum(unionAll)+ smooth)
错误我得到:
无效的人(请参见上文,请参阅上面的追踪(:您必须喂养一个值 用于占位符张量'activation_1_target'带dtype float和 shape [?,?,?] [[node:activation_1_target = = OptarholderDtype = dt_float,shape = [?,?,?],, _device ="/job:localhost/replica:0/task:0/gpu:0"]] recv_device ="/job:localhost/replica:0/任务:0/cpu:0", send_device ="/job:localhost/replica:0/任务:0/gpu:0", send_device_incarnation = 1,tensor_name =" edge_8_metrics/iou/reshape", tensor_type = dt_float, _device ="/job:localhost/replica:0/任务:0/cpu:0"]
eps = 1.
def iou(y_true, y_pred):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f*y_pred_f)
union = K.sum(y_true_f)+K.sum(y_pred_f)-intersection+eps
return intersection/union