我正在尝试进行一些图像比较,首先通过查找Jaccard指数。我正在使用sklearn.metrics实现的Jaccard Index。使用下面仅有的一小组数字的示例,它按预期工作。
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)
尽管它出现了一个错误...
ValueError: unknown is not supported
当我输入两张图片,例如......
iou = jaccard_similarity_score(img_true, img_pred)
我不确定该怎么做,我试着使用OpenCV将图像转换为灰度,并将两张图片都astype(float),但无论哪种情况都没有成功。
img_true.flatten()
看看会发生什么。 - Jason Stein