From 89b407c5648e79e25ad8374cca2103552f10fbe6 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 31 Jul 2025 16:57:59 -0600 Subject: [PATCH] feat: only copy images with confidence over 95% Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) --- sort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sort.py b/sort.py index 47c46ab..e514965 100644 --- a/sort.py +++ b/sort.py @@ -13,6 +13,7 @@ def sort_images(): MODEL_PATH = 'garage_door_cnn.pth' SOURCE_DIR = 'data/hourly_photos/' DEST_DIR = 'data/sorted/open/' + CONFIDENCE_THRESHOLD = 0.95 # Only copy if confidence is over this value # The classes are sorted alphabetically by ImageFolder: ['closed', 'open'] @@ -63,7 +64,7 @@ def sort_images(): probabilities = F.softmax(output, dim=1) confidence, pred_idx = torch.max(probabilities, 1) - if pred_idx.item() == TARGET_CLASS_IDX: + if pred_idx.item() == TARGET_CLASS_IDX and confidence.item() > CONFIDENCE_THRESHOLD: print(f"Found 'open' image: {file_path} with confidence: {confidence.item():.4f}") # Copy file shutil.copy(file_path, os.path.join(DEST_DIR, filename))