How to use jaccardindex to calculate binary IOU? #1133
Unanswered
ress4859
asked this question in
Classification
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
my target shape is (8,1,224,224),my pred shape is also (8,1,224,224).
Target consists of 0 and 1,I just want to calculate the IOU of 1.
if i set num_classes=1 , it will report that RuntimeError shape '[1, 1]' is invalid for input of size 2.
if i set num_classes =2,The output value of jaccardindex is incorrect.I use jaccardindex like this:
iou_metrics = JaccardIndex(num_classes=2, ignore_index=0).to(device)
iou = iou_metrics(output[0].squeeze(dim=1), target.type(torch.int).squeeze(dim=1) )
The value of iou is different from the result calculated by the following code:
def iou_score(output, target):
smooth = 1e-7
if torch.is_tensor(output):
output = torch.sigmoid(output).data.cpu().numpy()
if torch.is_tensor(target):
target = target.data.cpu().numpy()
output_ = output > 0.5
target_ = target > 0.5
intersection = (output_ & target_).sum()
union = (output_ | target_).sum()
return (intersection + smooth) / (union + smooth)
Beta Was this translation helpful? Give feedback.
All reactions