From 1be95732cbf8040f3035ae18d80da7e7a5f51f36 Mon Sep 17 00:00:00 2001 From: Marvo Lau <35420606+keepcreative@users.noreply.github.com> Date: Mon, 13 May 2024 19:58:59 +0800 Subject: [PATCH] Update spice.py Remove the NUL character at the end to avoid JSONDecodeError --- pycocoevalcap/spice/spice.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pycocoevalcap/spice/spice.py b/pycocoevalcap/spice/spice.py index e873471..959fc83 100644 --- a/pycocoevalcap/spice/spice.py +++ b/pycocoevalcap/spice/spice.py @@ -70,8 +70,10 @@ def compute_score(self, gts, res): cwd=os.path.dirname(os.path.abspath(__file__))) # Read and process results - with open(out_file.name) as data_file: - results = json.load(data_file) + # Remove the NUL character at the end to avoid JSONDecodeError + with open(out_file.name, 'r', encoding='utf-8') as data_file: + content = data_file.read().rstrip('\x00') + results = json.loads(content) os.remove(in_file.name) os.remove(out_file.name)