【问题标题】:IoU keras (backend tensorflow) feed dict for placeholder error (tensor.eval()IoU keras(后端张量流)为占位符错误提供字典(tensor.eval()
【发布时间】:2018-08-01 09:30:02
【问题描述】:

当我尝试为 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)

我得到的错误

InvalidArgumentError(参见上面的回溯):您必须输入一个值 对于具有 dtype 浮点数的占位符张量“activation_1_target”和 形状 [?,?,?] [[节点:activation_1_target = Placeholderdtype=DT_FLOAT, shape=[?,?,?], _device="/job:localhost/replica:0/task:0/gpu:0"]] [[节点:metrics/IoU/Reshape/_5 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_8_metrics/IoU/Reshape", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]

【问题讨论】:

    标签: python tensorflow deep-learning keras keras-2


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 2019-04-15
      • 2019-02-08
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      相关资源
      最近更新 更多