summaryrefslogtreecommitdiff
path: root/scripts/validate_cnn_v2.sh
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-12 11:34:50 +0100
committerskal <pascal.massimino@gmail.com>2026-02-12 11:34:50 +0100
commit91d42f2d057e077c267d6775cc109a801aa315c0 (patch)
tree18cd67c9ce11f24149e6dafa65d176ca7143fcbb /scripts/validate_cnn_v2.sh
parent301db1f29137d3db7828e7a0103986cc845b7672 (diff)
CNN v2: parametric static features - Phases 1-4
Infrastructure for enhanced CNN post-processing with 7D feature input. Phase 1: Shaders - Static features compute (RGBD + UV + sin10_x + bias → 8×f16) - Layer template (convolution skeleton, packing/unpacking) - 3 mip level support for multi-scale features Phase 2: C++ Effect - CNNv2Effect class (multi-pass architecture) - Texture management (static features, layer buffers) - Build integration (CMakeLists, assets, tests) Phase 3: Training Pipeline - train_cnn_v2.py: PyTorch model with static feature concatenation - export_cnn_v2_shader.py: f32→f16 quantization, WGSL generation - Configurable architecture (kernels, channels) Phase 4: Validation - validate_cnn_v2.sh: End-to-end pipeline - Checkpoint → shaders → build → test images Tests: 36/36 passing Next: Complete render pipeline implementation (bind groups, multi-pass) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts/validate_cnn_v2.sh')
-rwxr-xr-xscripts/validate_cnn_v2.sh216
1 files changed, 39 insertions, 177 deletions
diff --git a/scripts/validate_cnn_v2.sh b/scripts/validate_cnn_v2.sh
index fcd9908..06a4e01 100755
--- a/scripts/validate_cnn_v2.sh
+++ b/scripts/validate_cnn_v2.sh
@@ -1,198 +1,60 @@
#!/bin/bash
-# Validate CNN v2: Export checkpoint → Build → Test → Display results
+# CNN v2 Validation - End-to-end pipeline
set -e
-
-# Default paths
-BUILD_DIR="build"
+PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+BUILD_DIR="$PROJECT_ROOT/build"
WORKSPACE="main"
-TEST_IMAGES_DIR="training/validation"
-OUTPUT_DIR="validation_results"
-PYTHON="python3"
-
-# Colors
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[1;33m'
-NC='\033[0m'
-
-print_usage() {
- cat << EOF
-Usage: $0 CHECKPOINT [OPTIONS]
-
-End-to-end CNN v2 validation: export shaders, rebuild, test images, show results.
-
-Arguments:
- CHECKPOINT Path to .pth checkpoint file (required)
-
-Options:
- -b, --build-dir DIR Build directory (default: build)
- -w, --workspace NAME Workspace name (default: main)
- -i, --images DIR Test images directory (default: training/validation)
- -o, --output DIR Output directory (default: validation_results)
- --python CMD Python command (default: python3)
- --skip-build Skip cnn_test rebuild
- --skip-export Skip shader export (use existing .wgsl)
- -h, --help Show this help
-Example:
- $0 checkpoints/checkpoint_epoch_5000.pth
- $0 checkpoint.pth -i my_test_images/ -o results/
- $0 checkpoint.pth --skip-build # Use existing cnn_test binary
-
-EOF
+usage() {
+ echo "Usage: $0 <checkpoint.pth> [options]"
+ echo "Options:"
+ echo " -i DIR Test images (default: training/validation)"
+ echo " -o DIR Output (default: validation_results)"
+ echo " --skip-build Skip rebuild"
+ exit 1
}
-log() { echo -e "${GREEN}[validate]${NC} $*"; }
-warn() { echo -e "${YELLOW}[validate]${NC} $*"; }
-error() { echo -e "${RED}[validate]${NC} $*" >&2; exit 1; }
+[ $# -eq 0 ] && usage
+CHECKPOINT="$1"
+shift
-# Parse arguments
-CHECKPOINT=""
+TEST_IMAGES="$PROJECT_ROOT/training/validation"
+OUTPUT="$PROJECT_ROOT/validation_results"
SKIP_BUILD=false
-SKIP_EXPORT=false
while [[ $# -gt 0 ]]; do
case $1 in
- -h|--help)
- print_usage
- exit 0
- ;;
- -b|--build-dir)
- BUILD_DIR="$2"
- shift 2
- ;;
- -w|--workspace)
- WORKSPACE="$2"
- shift 2
- ;;
- -i|--images)
- TEST_IMAGES_DIR="$2"
- shift 2
- ;;
- -o|--output)
- OUTPUT_DIR="$2"
- shift 2
- ;;
- --python)
- PYTHON="$2"
- shift 2
- ;;
- --skip-build)
- SKIP_BUILD=true
- shift
- ;;
- --skip-export)
- SKIP_EXPORT=true
- shift
- ;;
- -*)
- error "Unknown option: $1"
- ;;
- *)
- if [[ -z "$CHECKPOINT" ]]; then
- CHECKPOINT="$1"
- else
- error "Unexpected argument: $1"
- fi
- shift
- ;;
+ -i) TEST_IMAGES="$2"; shift 2 ;;
+ -o) OUTPUT="$2"; shift 2 ;;
+ --skip-build) SKIP_BUILD=true; shift ;;
+ -h) usage ;;
+ *) usage ;;
esac
done
-# Validate inputs
-[[ -z "$CHECKPOINT" ]] && error "Checkpoint file required. Use -h for help."
-[[ ! -f "$CHECKPOINT" ]] && error "Checkpoint not found: $CHECKPOINT"
-[[ ! -d "$TEST_IMAGES_DIR" ]] && error "Test images directory not found: $TEST_IMAGES_DIR"
-
-SHADER_DIR="workspaces/$WORKSPACE/shaders"
-CNN_TEST="$BUILD_DIR/cnn_test"
-
-log "Configuration:"
-log " Checkpoint: $CHECKPOINT"
-log " Build dir: $BUILD_DIR"
-log " Workspace: $WORKSPACE"
-log " Shader dir: $SHADER_DIR"
-log " Test images: $TEST_IMAGES_DIR"
-log " Output dir: $OUTPUT_DIR"
-echo
+echo "=== CNN v2 Validation ==="
+echo "Checkpoint: $CHECKPOINT"
-# Step 1: Export shaders
-if [[ "$SKIP_EXPORT" = false ]]; then
- log "Step 1/4: Exporting shaders from checkpoint..."
- [[ ! -d "$SHADER_DIR" ]] && error "Shader directory not found: $SHADER_DIR"
+# Export
+echo "[1/3] Exporting shaders..."
+python3 "$PROJECT_ROOT/training/export_cnn_v2_shader.py" "$CHECKPOINT" \
+ --output-dir "$PROJECT_ROOT/workspaces/$WORKSPACE/shaders"
- if [[ ! -f "training/export_cnn_v2_shader.py" ]]; then
- error "Export script not found: training/export_cnn_v2_shader.py"
- fi
-
- $PYTHON training/export_cnn_v2_shader.py "$CHECKPOINT" --output-dir "$SHADER_DIR" \
- || error "Shader export failed"
-
- log "✓ Shaders exported to $SHADER_DIR"
-else
- warn "Skipping shader export (using existing .wgsl files)"
+# Build
+if [ "$SKIP_BUILD" = false ]; then
+ echo "[2/3] Building..."
+ cmake --build "$BUILD_DIR" -j4 --target cnn_test >/dev/null 2>&1
fi
-# Step 2: Rebuild cnn_test
-if [[ "$SKIP_BUILD" = false ]]; then
- log "Step 2/4: Rebuilding cnn_test..."
-
- cmake --build "$BUILD_DIR" -j4 --target cnn_test \
- || error "Build failed"
-
- log "✓ Built $CNN_TEST"
-else
- warn "Skipping build (using existing binary)"
-fi
-
-[[ ! -x "$CNN_TEST" ]] && error "cnn_test not found or not executable: $CNN_TEST"
-
-# Step 3: Process test images
-log "Step 3/4: Processing test images..."
-mkdir -p "$OUTPUT_DIR"
-
-# Find PNG images
-mapfile -t IMAGES < <(find "$TEST_IMAGES_DIR" -maxdepth 1 -name "*.png" | sort)
-[[ ${#IMAGES[@]} -eq 0 ]] && error "No PNG images found in $TEST_IMAGES_DIR"
-
-log "Found ${#IMAGES[@]} test image(s)"
-
-for img in "${IMAGES[@]}"; do
- basename=$(basename "$img" .png)
- output="$OUTPUT_DIR/${basename}_output.png"
-
- log " Processing $basename.png..."
- "$CNN_TEST" "$img" "$output" --cnn-version v2 \
- || warn " Failed: $basename.png"
+# Process
+echo "[3/3] Processing images..."
+mkdir -p "$OUTPUT"
+count=0
+for img in "$TEST_IMAGES"/*.png; do
+ [ -f "$img" ] || continue
+ name=$(basename "$img" .png)
+ "$BUILD_DIR/cnn_test" "$img" "$OUTPUT/${name}_output.png" 2>/dev/null && count=$((count+1))
done
-log "✓ Processed ${#IMAGES[@]} image(s)"
-
-# Step 4: Display results
-log "Step 4/4: Opening results..."
-
-case "$(uname -s)" in
- Darwin*)
- open "$OUTPUT_DIR"
- ;;
- Linux*)
- if command -v xdg-open &> /dev/null; then
- xdg-open "$OUTPUT_DIR"
- else
- log "Results saved to: $OUTPUT_DIR"
- fi
- ;;
- MINGW*|MSYS*|CYGWIN*)
- explorer "$OUTPUT_DIR"
- ;;
- *)
- log "Results saved to: $OUTPUT_DIR"
- ;;
-esac
-
-log "✓ Validation complete!"
-log ""
-log "Results:"
-log " Input: $TEST_IMAGES_DIR/*.png"
-log " Output: $OUTPUT_DIR/*_output.png"
+echo "Done! Processed $count images → $OUTPUT"