| # 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" | |