将 sklearn.metrics Jaccard Index 与图像一起使用?

Car*_*son 3 python opencv numpy scikit-learn

我正在尝试进行一些图像比较,首先从查找杰卡德索引开始。我正在使用 Jaccard Index 的 sklearn.metrics 实现,使用下面的示例以及一小部分数字,它的工作原理与预期一致。

import numpy as np
from sklearn.metrics import jaccard_similarity_score

#The y_pred represents the values that the program has found 
y_pred = [0,0,1,0,0,0,1,1,1,1,0,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,1,1,0,0,1,1,0,1,1,1]
#The y_true represents the values that are actually correct 
y_true = [1,0,0,1,0,1,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,1,0,0,0,0,1,1,1,0,1,0,1,1,1]

iou = jaccard_similarity_score(y_true, y_pred)
Run Code Online (Sandbox Code Playgroud)

虽然它给出了一个错误......

ValueError: unknown is not supported
Run Code Online (Sandbox Code Playgroud)

当我给它喂两个图像时,例如......

iou = jaccard_similarity_score(img_true, img_pred)
Run Code Online (Sandbox Code Playgroud)

我不确定该怎么做,我尝试使用 OpenCV 将图像转换为灰度并将这两个图像设置为类型(浮动),但在任何一种情况下都没有运气。

Jas*_*ein 6

作为答案发布,以便可以关闭问题:通过执行和解决扁平化img_true和解决img_predimg_true.flatten()img_pred.flatten()