Add margin check to multi-ref matching to reduce false positives
The multi-ref matching method was missing a margin check against other logos, causing excessive false positives. This fix adds: - margin parameter to find_best_match_multi_ref() that requires the best logo's score to exceed the second-best by a minimum margin - Test script now passes --margin to both matching methods - Updated documentation to reflect margin applies to both methods Also adds run_comparison_tests.sh to run all three matching methods and compare results.
This commit is contained in:
76
run_comparison_tests.sh
Executable file
76
run_comparison_tests.sh
Executable file
@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Run logo detection tests with all three matching methods and save results.
|
||||
#
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
OUTPUT_FILE="${SCRIPT_DIR}/comparison_results.txt"
|
||||
|
||||
# Common parameters
|
||||
NUM_LOGOS=20
|
||||
REFS_PER_LOGO=10
|
||||
POSITIVE_SAMPLES=20
|
||||
NEGATIVE_SAMPLES=100
|
||||
MIN_MATCHING_REFS=3
|
||||
|
||||
# Use a fixed seed for reproducibility across methods
|
||||
SEED=42
|
||||
|
||||
echo "Logo Detection Comparison Tests" > "$OUTPUT_FILE"
|
||||
echo "================================" >> "$OUTPUT_FILE"
|
||||
echo "Date: $(date)" >> "$OUTPUT_FILE"
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
|
||||
echo "Running tests with:"
|
||||
echo " Reference logos: $NUM_LOGOS"
|
||||
echo " Refs per logo: $REFS_PER_LOGO"
|
||||
echo " Positive samples: $POSITIVE_SAMPLES"
|
||||
echo " Negative samples: $NEGATIVE_SAMPLES"
|
||||
echo " Min matching refs: $MIN_MATCHING_REFS"
|
||||
echo " Seed: $SEED"
|
||||
echo ""
|
||||
|
||||
# Test 1: Margin-based matching
|
||||
echo "=== Test 1: Margin-based matching ===" | tee -a "$OUTPUT_FILE"
|
||||
uv run python "$SCRIPT_DIR/test_logo_detection.py" \
|
||||
--num-logos $NUM_LOGOS \
|
||||
--refs-per-logo $REFS_PER_LOGO \
|
||||
--positive-samples $POSITIVE_SAMPLES \
|
||||
--negative-samples $NEGATIVE_SAMPLES \
|
||||
--matching-method margin \
|
||||
--seed $SEED \
|
||||
2>&1 | tee -a "$OUTPUT_FILE"
|
||||
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
|
||||
# Test 2: Multi-ref with mean similarity
|
||||
echo "=== Test 2: Multi-ref matching (mean similarity) ===" | tee -a "$OUTPUT_FILE"
|
||||
uv run python "$SCRIPT_DIR/test_logo_detection.py" \
|
||||
--num-logos $NUM_LOGOS \
|
||||
--refs-per-logo $REFS_PER_LOGO \
|
||||
--positive-samples $POSITIVE_SAMPLES \
|
||||
--negative-samples $NEGATIVE_SAMPLES \
|
||||
--matching-method multi-ref \
|
||||
--min-matching-refs $MIN_MATCHING_REFS \
|
||||
--seed $SEED \
|
||||
2>&1 | tee -a "$OUTPUT_FILE"
|
||||
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
|
||||
# Test 3: Multi-ref with max similarity
|
||||
echo "=== Test 3: Multi-ref matching (max similarity) ===" | tee -a "$OUTPUT_FILE"
|
||||
uv run python "$SCRIPT_DIR/test_logo_detection.py" \
|
||||
--num-logos $NUM_LOGOS \
|
||||
--refs-per-logo $REFS_PER_LOGO \
|
||||
--positive-samples $POSITIVE_SAMPLES \
|
||||
--negative-samples $NEGATIVE_SAMPLES \
|
||||
--matching-method multi-ref \
|
||||
--min-matching-refs $MIN_MATCHING_REFS \
|
||||
--use-max-similarity \
|
||||
--seed $SEED \
|
||||
2>&1 | tee -a "$OUTPUT_FILE"
|
||||
|
||||
echo ""
|
||||
echo "Results saved to: $OUTPUT_FILE"
|
||||
Reference in New Issue
Block a user