import sys import sys import os sys.path.append(os.path.join(os.path.dirname(__file__), "../env")) import pandas as pd from encode import rle_decode import numpy as np def dice_score(y_p, y_t, smooth=1e-6): i = np.sum(y_p * y_t) u = np.sum(y_p) + np.sum(y_t) score = (2 * i + smooth)/(u + smooth) return score def get_score(submission_folder = "../env"): submission_path = os.path.join(submission_folder, "submission.csv") submission = pd.read_csv(submission_path, index_col='record_id') ids = os.listdir(os.path.join(os.path.dirname(__file__), "test_answer")) total_score = 0 for id in ids: pred = submission.loc[int(id), 'encoded_pixels'] pred = rle_decode(pred) score = dice_score(pred, np.load(f"{os.path.dirname(__file__)}/test_answer/{id}/human_pixel_masks.npy")[:,:,0]) total_score += score return total_score/len(ids) if __name__ == "__main__": print(get_score())