diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/gemini_commit.bat | 7 | ||||
| -rwxr-xr-x | scripts/gemini_commit.sh | 6 | ||||
| -rw-r--r-- | scripts/gemini_end.bat | 5 | ||||
| -rwxr-xr-x | scripts/gemini_end.sh | 5 | ||||
| -rw-r--r-- | scripts/gemini_start.bat | 8 | ||||
| -rwxr-xr-x | scripts/gemini_start.sh | 6 | ||||
| -rwxr-xr-x | scripts/train_cnn_v2_full.sh | 288 |
7 files changed, 220 insertions, 105 deletions
diff --git a/scripts/gemini_commit.bat b/scripts/gemini_commit.bat deleted file mode 100644 index f9d922c..0000000 --- a/scripts/gemini_commit.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off -REM Ask Gemini to summarize work and update docs - -gemini --files ^ - TASKS.md ^ - NOTES.md ^ - "Summarize what was accomplished. Update TASKS.md with next steps." diff --git a/scripts/gemini_commit.sh b/scripts/gemini_commit.sh deleted file mode 100755 index ae327e4..0000000 --- a/scripts/gemini_commit.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# Ask Gemini to summarize work and update docs - -gemini --files TASKS.md NOTES.md "Summarize what was accomplished. - Update TASKS.md with next steps. - Add warnings or decisions to NOTES.md." diff --git a/scripts/gemini_end.bat b/scripts/gemini_end.bat deleted file mode 100644 index ab4beba..0000000 --- a/scripts/gemini_end.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -REM End-of-session summary - -gemini --files PROJECT_CONTEXT.md ^ - "Confirm no constraints were violated. Provide a short summary." diff --git a/scripts/gemini_end.sh b/scripts/gemini_end.sh deleted file mode 100755 index 5689acf..0000000 --- a/scripts/gemini_end.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# End-of-session summary - -gemini --files PROJECT_CONTEXT.md "Confirm no project constraints were violated. - Provide a short end-of-session summary." diff --git a/scripts/gemini_start.bat b/scripts/gemini_start.bat deleted file mode 100644 index 22bca70..0000000 --- a/scripts/gemini_start.bat +++ /dev/null @@ -1,8 +0,0 @@ -@echo off -REM Start a Gemini session with core context - -gemini --files ^ - PROJECT_CONTEXT.md ^ - BUILD.md ^ - PHASE2_COMPRESSION.md ^ - "Read the project context carefully. Summarize the project goals and current phase. Wait." diff --git a/scripts/gemini_start.sh b/scripts/gemini_start.sh deleted file mode 100755 index ea11bea..0000000 --- a/scripts/gemini_start.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# Start a Gemini session with core context - -gemini --files PROJECT_CONTEXT.md BUILD.md PHASE2_COMPRESSION.md "Read the project context carefully. - Summarize the project goals and current phase. - Wait for further instructions." diff --git a/scripts/train_cnn_v2_full.sh b/scripts/train_cnn_v2_full.sh index 6468d12..766bd8b 100755 --- a/scripts/train_cnn_v2_full.sh +++ b/scripts/train_cnn_v2_full.sh @@ -3,35 +3,93 @@ # Train → Export → Build → Validate # Usage: ./train_cnn_v2_full.sh [OPTIONS] # -# OPTIONS: +# MODES: # (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) -# --mip-level LEVEL Mip level for p0-p3 features: 0=original, 1=half, 2=quarter, 3=eighth (default: 0) +# +# TRAINING PARAMETERS: +# --epochs N Training epochs (default: 200) +# --batch-size N Batch size (default: 16) +# --checkpoint-every N Checkpoint interval (default: 50) +# --kernel-sizes K Comma-separated kernel sizes (default: 3,3,3) +# --num-layers N Number of layers (default: 3) +# --mip-level N Mip level for p0-p3 features: 0-3 (default: 0) +# --grayscale-loss Compute loss on grayscale instead of RGBA +# +# PATCH PARAMETERS: +# --patch-size N Patch size (default: 8) +# --patches-per-image N Patches per image (default: 256) +# --detector TYPE Detector: harris|fast|shi-tomasi|gradient (default: harris) +# --full-image Use full-image training (disables patch mode) +# --image-size N Image size for full-image mode (default: 256) +# +# DIRECTORIES: +# --input DIR Input directory (default: training/input) +# --target DIR Target directory (default: training/target_1) +# --checkpoint-dir DIR Checkpoint directory (default: checkpoints) +# --validation-dir DIR Validation directory (default: validation_results) +# +# OUTPUT: +# --output-weights PATH Output binary weights file (default: workspaces/main/weights/cnn_v2_weights.bin) +# +# OTHER: # --help Show this help message # # Examples: # ./train_cnn_v2_full.sh +# ./train_cnn_v2_full.sh --epochs 500 --batch-size 32 # ./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 -# ./train_cnn_v2_full.sh --mip-level 1 +# ./train_cnn_v2_full.sh --mip-level 1 --kernel-sizes 3,5,3 set -e PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$PROJECT_ROOT" +# Helper functions +export_weights() { + python3 training/export_cnn_v2_weights.py "$1" --output-weights "$2" --quiet +} + +find_latest_checkpoint() { + ls -t "$CHECKPOINT_DIR"/checkpoint_epoch_*.pth 2>/dev/null | head -1 +} + +build_target() { + cmake --build build -j4 --target "$1" > /dev/null 2>&1 +} + +# Default configuration +INPUT_DIR="training/input" +TARGET_DIR="training/target_1" +CHECKPOINT_DIR="checkpoints" +VALIDATION_DIR="validation_results" +EPOCHS=200 +CHECKPOINT_EVERY=50 +BATCH_SIZE=16 +PATCH_SIZE=8 +PATCHES_PER_IMAGE=256 +DETECTOR="harris" +KERNEL_SIZES="3,3,3" +NUM_LAYERS=3 +MIP_LEVEL=0 +GRAYSCALE_LOSS=false +FULL_IMAGE_MODE=false +IMAGE_SIZE=256 +OUTPUT_WEIGHTS="workspaces/main/weights/cnn_v2_weights.bin" + # Parse arguments VALIDATE_ONLY=false VALIDATE_CHECKPOINT="" EXPORT_ONLY=false EXPORT_CHECKPOINT="" -MIP_LEVEL=0 if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then - head -21 "$0" | grep "^#" | grep -v "^#!/" | sed 's/^# *//' + head -47 "$0" | grep "^#" | grep -v "^#!/" | sed 's/^# *//' exit 0 fi @@ -56,6 +114,46 @@ while [[ $# -gt 0 ]]; do shift fi ;; + --epochs) + if [ -z "$2" ]; then + echo "Error: --epochs requires a number argument" + exit 1 + fi + EPOCHS="$2" + shift 2 + ;; + --batch-size) + if [ -z "$2" ]; then + echo "Error: --batch-size requires a number argument" + exit 1 + fi + BATCH_SIZE="$2" + shift 2 + ;; + --checkpoint-every) + if [ -z "$2" ]; then + echo "Error: --checkpoint-every requires a number argument" + exit 1 + fi + CHECKPOINT_EVERY="$2" + shift 2 + ;; + --kernel-sizes) + if [ -z "$2" ]; then + echo "Error: --kernel-sizes requires a comma-separated list" + exit 1 + fi + KERNEL_SIZES="$2" + shift 2 + ;; + --num-layers) + if [ -z "$2" ]; then + echo "Error: --num-layers requires a number argument" + exit 1 + fi + NUM_LAYERS="$2" + shift 2 + ;; --mip-level) if [ -z "$2" ]; then echo "Error: --mip-level requires a level argument (0-3)" @@ -64,6 +162,86 @@ while [[ $# -gt 0 ]]; do MIP_LEVEL="$2" shift 2 ;; + --grayscale-loss) + GRAYSCALE_LOSS=true + shift + ;; + --patch-size) + if [ -z "$2" ]; then + echo "Error: --patch-size requires a number argument" + exit 1 + fi + PATCH_SIZE="$2" + shift 2 + ;; + --patches-per-image) + if [ -z "$2" ]; then + echo "Error: --patches-per-image requires a number argument" + exit 1 + fi + PATCHES_PER_IMAGE="$2" + shift 2 + ;; + --detector) + if [ -z "$2" ]; then + echo "Error: --detector requires a type argument" + exit 1 + fi + DETECTOR="$2" + shift 2 + ;; + --full-image) + FULL_IMAGE_MODE=true + shift + ;; + --image-size) + if [ -z "$2" ]; then + echo "Error: --image-size requires a number argument" + exit 1 + fi + IMAGE_SIZE="$2" + shift 2 + ;; + --input) + if [ -z "$2" ]; then + echo "Error: --input requires a directory argument" + exit 1 + fi + INPUT_DIR="$2" + shift 2 + ;; + --target) + if [ -z "$2" ]; then + echo "Error: --target requires a directory argument" + exit 1 + fi + TARGET_DIR="$2" + shift 2 + ;; + --checkpoint-dir) + if [ -z "$2" ]; then + echo "Error: --checkpoint-dir requires a directory argument" + exit 1 + fi + CHECKPOINT_DIR="$2" + shift 2 + ;; + --validation-dir) + if [ -z "$2" ]; then + echo "Error: --validation-dir requires a directory argument" + exit 1 + fi + VALIDATION_DIR="$2" + shift 2 + ;; + --output-weights) + if [ -z "$2" ]; then + echo "Error: --output-weights requires a file path argument" + exit 1 + fi + OUTPUT_WEIGHTS="$2" + shift 2 + ;; *) echo "Unknown option: $1" exit 1 @@ -71,27 +249,12 @@ while [[ $# -gt 0 ]]; do esac done -# Configuration -INPUT_DIR="training/input" -TARGET_DIR="training/target_2" -CHECKPOINT_DIR="checkpoints" -VALIDATION_DIR="validation_results" -EPOCHS=200 -CHECKPOINT_EVERY=50 -BATCH_SIZE=16 - -# Patch-based training (default) -PATCH_SIZE=8 -PATCHES_PER_IMAGE=256 -DETECTOR="harris" - -# Full-image training (alternative - uncomment to use) -# FULL_IMAGE="--full-image" -# IMAGE_SIZE=256 - -KERNEL_SIZES="3,3,3" # Comma-separated per-layer kernel sizes -NUM_LAYERS=3 -# MIP_LEVEL set via --mip-level argument (default: 0) +# Build training arguments +if [ "$FULL_IMAGE_MODE" = true ]; then + TRAINING_MODE_ARGS="--full-image --image-size $IMAGE_SIZE" +else + TRAINING_MODE_ARGS="--patch-size $PATCH_SIZE --patches-per-image $PATCHES_PER_IMAGE --detector $DETECTOR" +fi # Handle export-only mode if [ "$EXPORT_ONLY" = true ]; then @@ -104,17 +267,14 @@ if [ "$EXPORT_ONLY" = true ]; then 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 + export_weights "$EXPORT_CHECKPOINT" "$OUTPUT_WEIGHTS" || { echo "Error: Export failed" exit 1 - fi + } echo "" echo "=== Export Complete ===" - echo "Output: workspaces/main/weights/cnn_v2_weights.bin" + echo "Output: $OUTPUT_WEIGHTS" exit 0 fi @@ -135,20 +295,19 @@ fi if [ "$VALIDATE_ONLY" = false ]; then # Step 1: Train model echo "[1/4] Training CNN v2 model..." + python3 training/train_cnn_v2.py \ --input "$INPUT_DIR" \ --target "$TARGET_DIR" \ - --patch-size $PATCH_SIZE \ - --patches-per-image $PATCHES_PER_IMAGE \ - --detector $DETECTOR \ - --kernel-sizes $KERNEL_SIZES \ - --num-layers $NUM_LAYERS \ - --mip-level $MIP_LEVEL \ - --epochs $EPOCHS \ - --batch-size $BATCH_SIZE \ + $TRAINING_MODE_ARGS \ + --kernel-sizes "$KERNEL_SIZES" \ + --num-layers "$NUM_LAYERS" \ + --mip-level "$MIP_LEVEL" \ + --epochs "$EPOCHS" \ + --batch-size "$BATCH_SIZE" \ --checkpoint-dir "$CHECKPOINT_DIR" \ - --checkpoint-every $CHECKPOINT_EVERY \ - $FULL_IMAGE + --checkpoint-every "$CHECKPOINT_EVERY" \ + $([ "$GRAYSCALE_LOSS" = true ] && echo "--grayscale-loss") if [ $? -ne 0 ]; then echo "Error: Training failed" @@ -164,30 +323,27 @@ FINAL_CHECKPOINT="$CHECKPOINT_DIR/checkpoint_epoch_${EPOCHS}.pth" if [ ! -f "$FINAL_CHECKPOINT" ]; then echo "Warning: Final checkpoint not found, using latest available..." - FINAL_CHECKPOINT=$(ls -t "$CHECKPOINT_DIR"/checkpoint_epoch_*.pth | head -1) + FINAL_CHECKPOINT=$(find_latest_checkpoint) +fi + +if [ -z "$FINAL_CHECKPOINT" ] || [ ! -f "$FINAL_CHECKPOINT" ]; then + echo "Error: No checkpoint found in $CHECKPOINT_DIR" + exit 1 fi echo "[2/4] Exporting final checkpoint to binary weights..." echo "Checkpoint: $FINAL_CHECKPOINT" -python3 training/export_cnn_v2_weights.py "$FINAL_CHECKPOINT" \ - --output-weights workspaces/main/weights/cnn_v2_weights.bin - -if [ $? -ne 0 ]; then +export_weights "$FINAL_CHECKPOINT" "$OUTPUT_WEIGHTS" || { echo "Error: Shader export failed" exit 1 -fi +} echo "" fi # End of training/export section # Determine which checkpoint to use if [ "$VALIDATE_ONLY" = true ]; then - if [ -n "$VALIDATE_CHECKPOINT" ]; then - FINAL_CHECKPOINT="$VALIDATE_CHECKPOINT" - else - # Use latest checkpoint - FINAL_CHECKPOINT=$(ls -t "$CHECKPOINT_DIR"/checkpoint_epoch_*.pth | head -1) - fi + FINAL_CHECKPOINT="${VALIDATE_CHECKPOINT:-$(find_latest_checkpoint)}" echo "Using checkpoint: $FINAL_CHECKPOINT" echo "" fi @@ -195,13 +351,10 @@ fi # Step 3: Rebuild with new shaders if [ "$VALIDATE_ONLY" = false ]; then echo "[3/4] Rebuilding demo with new shaders..." - cmake --build build -j4 --target demo64k > /dev/null 2>&1 - - if [ $? -ne 0 ]; then + build_target demo64k || { echo "Error: Build failed" exit 1 - fi - + } echo " → Build complete" echo "" fi @@ -218,24 +371,23 @@ echo " Using checkpoint: $FINAL_CHECKPOINT" # Export weights for validation mode (already exported in step 2 for training mode) if [ "$VALIDATE_ONLY" = true ]; then - python3 training/export_cnn_v2_weights.py "$FINAL_CHECKPOINT" \ - --output-weights workspaces/main/weights/cnn_v2_weights.bin > /dev/null 2>&1 + export_weights "$FINAL_CHECKPOINT" "$OUTPUT_WEIGHTS" > /dev/null 2>&1 fi # Build cnn_test -cmake --build build -j4 --target cnn_test > /dev/null 2>&1 +build_target cnn_test # Process all input images +echo -n " Processing images: " for input_image in "$INPUT_DIR"/*.png; do basename=$(basename "$input_image" .png) - echo " Processing $basename..." - build/cnn_test "$input_image" "$VALIDATION_DIR/${basename}_output.png" 2>/dev/null + echo -n "$basename " + build/cnn_test "$input_image" "$VALIDATION_DIR/${basename}_output.png" --weights "$OUTPUT_WEIGHTS" > /dev/null 2>&1 done +echo "✓" # Build demo only if not in validate mode -if [ "$VALIDATE_ONLY" = false ]; then - cmake --build build -j4 --target demo64k > /dev/null 2>&1 -fi +[ "$VALIDATE_ONLY" = false ] && build_target demo64k echo "" if [ "$VALIDATE_ONLY" = true ]; then @@ -247,7 +399,7 @@ echo "" echo "Results:" if [ "$VALIDATE_ONLY" = false ]; then echo " - Checkpoints: $CHECKPOINT_DIR" - echo " - Final weights: workspaces/main/weights/cnn_v2_weights.bin" + echo " - Final weights: $OUTPUT_WEIGHTS" fi echo " - Validation outputs: $VALIDATION_DIR" echo "" |
