From e9ecb6fbde52dadd299a9454485f238663d8dd99 Mon Sep 17 00:00:00 2001 From: MROS Date: Mon, 2 Jun 2025 10:44:06 +0800 Subject: [PATCH] Fix generate_cc_array treating empty CSV as single-element array Previously, an empty .csv file was incorrectly interpreted as a single-element array due to the behavior of str.split(',') on empty strings returning [''] (length 1). This patch explicitly checks for empty or whitespace-only lines and correctly returns a size of 0 and an empty array definition. --- tensorflow/lite/micro/tools/generate_cc_arrays.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tensorflow/lite/micro/tools/generate_cc_arrays.py b/tensorflow/lite/micro/tools/generate_cc_arrays.py index 16d72c12016..214b33866f8 100644 --- a/tensorflow/lite/micro/tools/generate_cc_arrays.py +++ b/tensorflow/lite/micro/tools/generate_cc_arrays.py @@ -86,6 +86,8 @@ def generate_array(input_fname): with open(input_fname, 'r') as input_file: # Assume one array per csv file. elements = input_file.readline() + if elements.strip() == "": + return [0, ""] return [len(elements.split(',')), elements] elif input_fname.endswith('.npy'): data = np.float32(np.load(input_fname, allow_pickle=False))