Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'do_kaggle_metric' is not defined #2

Open
adreamero opened this issue Nov 15, 2020 · 1 comment
Open

NameError: name 'do_kaggle_metric' is not defined #2

adreamero opened this issue Nov 15, 2020 · 1 comment

Comments

@adreamero
Copy link

您好,我运行您的程序的时候出现这个错误,这个是一个我没有导入的库吗?怎么解决呢?

100%|██████████| 3190/3190 [00:17<00:00, 184.54it/s]
100%|██████████| 810/810 [00:03<00:00, 239.47it/s]
Traceback (most recent call last):
File "F:/python_programs/SaltChallenge/Unet.py", line 332, in
val_loss, accuracy = test(val_loader, salt)
File "F:/python_programs/SaltChallenge/Unet.py", line 273, in test
precision, _, _ = do_kaggle_metric(predicts, truths, 0.5)
NameError: name 'do_kaggle_metric' is not defined

Process finished with exit code 1

@Qiuyan918
Copy link
Owner

def do_kaggle_metric(predict,truth, threshold=0.5):

    N = len(predict)
    predict = predict.reshape(N,-1)
    truth   = truth.reshape(N,-1)

    predict = predict>threshold
    truth   = truth>0.5
    intersection = truth & predict
    union        = truth | predict
    iou = intersection.sum(1)/(union.sum(1)+1e-8)

    #-------------------------------------------
    result = []
    precision = []
    is_empty_truth   = (truth.sum(1)==0)
    is_empty_predict = (predict.sum(1)==0)

    threshold = np.array([0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95])
    for t in threshold:
        p = iou>=t

        tp  = (~is_empty_truth)  & (~is_empty_predict) & (iou> t)
        fp  = (~is_empty_truth)  & (~is_empty_predict) & (iou<=t)
        fn  = (~is_empty_truth)  & ( is_empty_predict)
        fp_empty = ( is_empty_truth)  & (~is_empty_predict)
        tn_empty = ( is_empty_truth)  & ( is_empty_predict)

        p = (tp + tn_empty) / (tp + tn_empty + fp + fp_empty + fn)

        result.append( np.column_stack((tp,fp,fn,tn_empty,fp_empty)) )
        precision.append(p)

    result = np.array(result).transpose(1,2,0)
    precision = np.column_stack(precision)
    precision = precision.mean(1)

    return precision, result, threshold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants