From 2b3261eae270fd6ddc711680970b8707345f0656 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 13 Feb 2026 13:48:05 +0100 Subject: Add --export-only option to train_cnn_v2_full.sh Allows exporting weights from a checkpoint without training or validation. Co-Authored-By: Claude Sonnet 4.5 --- scripts/train_cnn_v2_full.sh | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'scripts/train_cnn_v2_full.sh') diff --git a/scripts/train_cnn_v2_full.sh b/scripts/train_cnn_v2_full.sh index 5a4e55e..99c104a 100755 --- a/scripts/train_cnn_v2_full.sh +++ b/scripts/train_cnn_v2_full.sh @@ -7,12 +7,14 @@ # (none) Run complete pipeline: train → export → build → validate # --validate Validate only (skip training, use existing weights) # --validate CHECKPOINT Validate with specific checkpoint file +# --export-only CHECKPOINT Export weights only (skip training, build, validation) # --help Show this help message # # Examples: # ./train_cnn_v2_full.sh # ./train_cnn_v2_full.sh --validate # ./train_cnn_v2_full.sh --validate checkpoints/checkpoint_epoch_50.pth +# ./train_cnn_v2_full.sh --export-only checkpoints/checkpoint_epoch_100.pth set -e @@ -22,13 +24,22 @@ cd "$PROJECT_ROOT" # Parse arguments VALIDATE_ONLY=false VALIDATE_CHECKPOINT="" +EXPORT_ONLY=false +EXPORT_CHECKPOINT="" if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then head -20 "$0" | grep "^#" | grep -v "^#!/" | sed 's/^# *//' exit 0 fi -if [ "$1" = "--validate" ]; then +if [ "$1" = "--export-only" ]; then + EXPORT_ONLY=true + if [ -z "$2" ]; then + echo "Error: --export-only requires a checkpoint file argument" + exit 1 + fi + EXPORT_CHECKPOINT="$2" +elif [ "$1" = "--validate" ]; then VALIDATE_ONLY=true if [ -n "$2" ]; then VALIDATE_CHECKPOINT="$2" @@ -56,6 +67,31 @@ DETECTOR="harris" KERNEL_SIZES="3,3,3" # Comma-separated per-layer kernel sizes NUM_LAYERS=3 +# Handle export-only mode +if [ "$EXPORT_ONLY" = true ]; then + echo "=== CNN v2 Export Weights Only ===" + echo "Checkpoint: $EXPORT_CHECKPOINT" + echo "" + + if [ ! -f "$EXPORT_CHECKPOINT" ]; then + echo "Error: Checkpoint file not found: $EXPORT_CHECKPOINT" + exit 1 + fi + + python3 training/export_cnn_v2_weights.py "$EXPORT_CHECKPOINT" \ + --output-weights workspaces/main/weights/cnn_v2_weights.bin + + if [ $? -ne 0 ]; then + echo "Error: Export failed" + exit 1 + fi + + echo "" + echo "=== Export Complete ===" + echo "Output: workspaces/main/weights/cnn_v2_weights.bin" + exit 0 +fi + if [ "$VALIDATE_ONLY" = true ]; then echo "=== CNN v2 Validation Only ===" echo "Skipping training, using existing weights" -- cgit v1.2.3