Skip to content

Instantly share code, notes, and snippets.

@tnarihi
Created September 29, 2015 03:53
Show Gist options
  • Save tnarihi/8cd9a574e892b8f0ea22 to your computer and use it in GitHub Desktop.
Save tnarihi/8cd9a574e892b8f0ea22 to your computer and use it in GitHub Desktop.
Compute WHDR
import numpy as np
def compute_hdr_whdr_core(pred, tar, w):
"""Compute HDR and WHDR of pairs in a single image
Args:
pred : 1d array, predicition
tar : 1d array, target
w : 1d array, weights (confidence)
Returns:
hdr : float
whdr : float
"""
err = (pred != tar)
hdr = err.sum() * 1. / err.size
whdr = (err * w).sum() / w.sum()
return hdr, whdr
def compute_hdr_whdr(scores, tar, weight):
"""Compute HDR and WHDR over images
Args:
scors : iterable of 1d arrays of predictions
tar : iterable of 1d arrays of targets
weight : iterable of 1d arrays of weights (confidence)
Returns:
hdr : 1d array of HDR
whdr : 1d array of WHDR
"""
hdr, whdr = (), ()
for i in xrange(len(scores)):
r = scores[i]
t = tar[i]
w = weight[i]
hdr_, whdr_= compute_hdr_whdr_core(r, t, w)
hdr += hdr_,
whdr += whdr_,
return np.array(hdr), np.array(whdr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment