Using sklearn.metrics Jaccard Index with images?

Viewed 6213

I am trying to do some image comparisons, starting first by finding the Jaccard Index. I'm using the sklearn.metrics implementation of Jaccard Index Using the example below with just a small array of numbers, it works like expected.

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)

Though it is giving an error of...

ValueError: unknown is not supported

When I feed it the two images such as....

iou = jaccard_similarity_score(img_true, img_pred)

I'm unsure what to do, I tried converting the images to grayscale using OpenCV and making both the images astype(float) with no luck in either case.

2 Answers
Related