diff --git a/detect.py b/detect.py index f404a2503..ac18f3c36 100644 --- a/detect.py +++ b/detect.py @@ -219,9 +219,10 @@ def run( def write_to_csv(image_name, prediction, confidence): """Writes prediction data for an image to a CSV file, appending if the file exists.""" data = {"Image Name": image_name, "Prediction": prediction, "Confidence": confidence} + file_exists = os.path.isfile(csv_path) with open(csv_path, mode="a", newline="") as f: writer = csv.DictWriter(f, fieldnames=data.keys()) - if not csv_path.is_file(): + if not file_exists: writer.writeheader() writer.writerow(data)