File size: 3,858 Bytes
31d2139 452723c 3e960d6 f91b4c8 31d2139 3e960d6 31d2139 f91b4c8 31d2139 | 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #!/bin/bash
# Script to perform image resizing at scale via multiprocessing.
# ===== Start of Configuration ====================================================
# INPUT_DIR="images/images1024x1024"
# OUTPUT_DIR="images/images512x512"
# EXT="png"
# TARGET_SIZE_W=512
# TARGET_SIZE_H=512
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/images512x512_matte_white_background"
# OUTPUT_DIR="images/images256x256_matte_white_background"
# EXT="png"
# TARGET_SIZE_W=256
# TARGET_SIZE_H=256
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/custom1024x1024_matte_white_background/male"
# OUTPUT_DIR="images/custom512x512_matte_white_background/male"
# EXT="png"
# TARGET_SIZE_W=512
# TARGET_SIZE_H=512
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/custom1024x1024_matte_white_background/female"
# OUTPUT_DIR="images/custom512x512_matte_white_background/female"
# EXT="png"
# TARGET_SIZE_W=512
# TARGET_SIZE_H=512
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/custom1024x1024_matte_white_background/male"
# OUTPUT_DIR="images/custom256x256_matte_white_background/male"
# EXT="png"
# TARGET_SIZE_W=256
# TARGET_SIZE_H=256
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/custom1024x1024_matte_white_background/female"
# OUTPUT_DIR="images/custom256x256_matte_white_background/female"
# EXT="png"
# TARGET_SIZE_W=256
# TARGET_SIZE_H=256
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/custom1024x1024_matte_white_background/female2"
# OUTPUT_DIR="images/custom512x512_matte_white_background/female2"
# EXT="png"
# TARGET_SIZE_W=512
# TARGET_SIZE_H=512
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
INPUT_DIR="images/custom1024x1024_matte_white_background/exemplars_male"
OUTPUT_DIR="images/custom512x512_matte_white_background/exemplars_male"
EXT="png"
TARGET_SIZE_W=512
TARGET_SIZE_H=512
MODE="lanczos" # nearest | bilinear | bicubic | lanczos
NUM_WORKERS=-1 # -1 to use all cpu cores
# INPUT_DIR="images/custom1024x1024_matte_white_background/exemplars_female"
# OUTPUT_DIR="images/custom512x512_matte_white_background/exemplars_female"
# EXT="png"
# TARGET_SIZE_W=512
# TARGET_SIZE_H=512
# MODE="lanczos" # nearest | bilinear | bicubic | lanczos
# NUM_WORKERS=-1 # -1 to use all cpu cores
# ===== End of Configuration ====================================================
log_dir="logs"
mkdir -p $log_dir
timestamp=$(date +"%Y%m%d_%H%M%S")
log_file="$log_dir/$timestamp.log"
start_time=$(date +"%Y-%m-%d %H:%M:%S")
start_sec=$(date +%s)
echo "Script started at: $start_time" | tee -a "$log_file"
python -m src.batch_image_resize \
--input_dir "$INPUT_DIR" \
--output_dir "$OUTPUT_DIR" \
--ext "$EXT" \
--mode "$MODE" \
--size $TARGET_SIZE_W $TARGET_SIZE_H \
--workers "$NUM_WORKERS" 2>&1 | tee -a "$log_file" # pipe outputs & err to log file too
end_time=$(date +"%Y-%m-%d %H:%M:%S")
end_sec=$(date +%s)
echo "Script ended at: $end_time" | tee -a "$log_file"
# Calculate duration in different formats
duration_sec=$((end_sec - start_sec))
duration_min=$(echo "scale=2; $duration_sec / 60" | bc)
duration_hr=$(echo "scale=2; $duration_sec / 3600" | bc)
echo "Total duration: " | tee -a "$log_file"
echo "- In hours: ${duration_hr} hours" | tee -a "$log_file"
echo "- In minutes: ${duration_min} minutes" | tee -a "$log_file"
echo "- In seconds: ${duration_sec} seconds" | tee -a "$log_file"
|