From e5e73c0ba7427e5525d4cbcc686e922afd10b6b8 Mon Sep 17 00:00:00 2001 From: nagadomi Date: Sat, 28 Apr 2018 11:04:53 +0900 Subject: [PATCH] Fix zero division error in jaccard --- tools/benchmark.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/benchmark.lua b/tools/benchmark.lua index 6beb72c..ebc7ae6 100644 --- a/tools/benchmark.lua +++ b/tools/benchmark.lua @@ -216,7 +216,12 @@ local function create_metric(metric) local num_a = ba:sum() local num_b = bb:sum() local a_and_b = ba:cmul(bb):sum() - return (a_and_b / (num_a + num_b - a_and_b)) + local abab = (num_a + num_b - a_and_b) + if abab > 0 then + return (a_and_b / abab) + else + return 1 + end end} else error("unknown metric: " .. metric) @@ -615,10 +620,10 @@ local function load_data_from_dir(test_dir) table.insert(test_x, {y = iproc.crop_mod4(img), basename = base}) end - if opt.show_progress then - xlua.progress(i, #files) - end if i % 10 == 0 then + if opt.show_progress then + xlua.progress(i, #files) + end collectgarbage() end end @@ -636,10 +641,10 @@ local function load_data_from_file(test_file) table.insert(test_x, {y = iproc.crop_mod4(img), basename = base}) end - if opt.show_progress then - xlua.progress(i, #files) - end if i % 10 == 0 then + if opt.show_progress then + xlua.progress(i, #files) + end collectgarbage() end end @@ -694,10 +699,10 @@ local function load_user_data(y_dir, y_file, x_dir, x_file) x = x, basename = key}) end - if opt.show_progress then - xlua.progress(i, #y_files) - end if i % 10 == 0 then + if opt.show_progress then + xlua.progress(i, #y_files) + end collectgarbage() end end