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.
Posting as answer so question can be closed: flattening img_true
and img_pred
solved by doing img_true.flatten()
and img_pred.flatten()
You can use ravel()
for converting it into 1-D:
img_true=np.array(img_true).ravel()
img_pred=np.array(img_pred).ravel()
iou = jaccard_similarity_score(img_true, img_pred)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With