File size: 2,082 Bytes
b7f710c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash

# Exit on any error
set -e

# Function to log messages
log_message() {
    local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
    echo "[${timestamp}] $1"
}

# Function to check if a command exists
command_exists() {
    command -v "$1" >/dev/null 2>&1
}

# Function to check if a file exists
check_file() {
    if [ ! -f "$1" ]; then
        log_message "ERROR: File $1 does not exist"
        exit 1
    fi
}

# Function to check if a directory exists
check_directory() {
    if [ ! -d "$1" ]; then
        log_message "ERROR: Directory $1 does not exist"
        exit 1
    fi
}

# Function to check Python and required tools
check_requirements() {
    log_message "Checking requirements..."
    if ! command_exists python3; then
        log_message "ERROR: Python3 is not installed"
        exit 1
    fi
}

# Main script execution
main() {
    log_message "Starting inference pipeline..."

    # Set variables with absolute paths
    SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
    PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
    INPUT_PATH="$PROJECT_ROOT/tests/test_images/Elon_Musk.jpg"
    MODEL_PATH="$PROJECT_ROOT/ckpts/SlimFace_regnet_y_800mf_full_model.pth"
    CONFIG_PATH="$PROJECT_ROOT/ckpts/index_to_class_mapping.json"
    SRC_DIR="$PROJECT_ROOT/src/slimface/inference"

    # Check if required files exist
    check_file "$INPUT_PATH"
    check_file "$MODEL_PATH"
    check_file "$CONFIG_PATH"
    check_directory "$SRC_DIR"

    # Check requirements
    check_requirements

    # Run inference
    log_message "Running inference..."
    python3 "${SRC_DIR}/inference.py" \
        --input_path "$INPUT_PATH" \
        --model_path "$MODEL_PATH" \
        --index_to_class_mapping_path "$CONFIG_PATH" || {
        log_message "ERROR: Inference failed"
        exit 1
    }

    log_message "Inference pipeline completed successfully"
}

# Trap Ctrl+C and exit gracefully
trap 'log_message "Script interrupted by user"; exit 1' INT

# Execute main function
main "$@"