#!/bin/bash # Script to perform image editing (replacing MASK_CLASSES with # BACKGROUND_COLOR) at scale via multiprocessing. # ===== Start of Configuration ==================================================== # SOURCE_DIR="images/images512x512" # OUTPUT_DIR="images/images512x512_black_background" # SEGMAP_DIR="segmaps/segmaps512x512" # MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils # BACKGROUND_COLOR="[0,0,0]" # EXT="png" # NUM_WORKERS=-1 # SOURCE_DIR="images/images512x512" # OUTPUT_DIR="images/images512x512_matte_white_background" # SEGMAP_DIR="segmaps/segmaps512x512" # MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils # BACKGROUND_COLOR="[225,225,225]" # matte_white # EXT="png" # NUM_WORKERS=-1 # SOURCE_DIR="images/custom1024x1024/male" # OUTPUT_DIR="images/custom1024x1024_matte_white_background/male" # SEGMAP_DIR="segmaps/custom1024x1024/male" # MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils # BACKGROUND_COLOR="[225,225,225]" # matte_white # EXT="png" # NUM_WORKERS=-1 # SOURCE_DIR="images/custom1024x1024/female" # OUTPUT_DIR="images/custom1024x1024_matte_white_background/female" # SEGMAP_DIR="segmaps/custom1024x1024/female" # MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils # BACKGROUND_COLOR="[225,225,225]" # matte_white # EXT="png" # NUM_WORKERS=-1 # SOURCE_DIR="images/custom1024x1024/female2" # OUTPUT_DIR="images/custom1024x1024_matte_white_background/female2" # SEGMAP_DIR="segmaps/custom1024x1024/female2" # MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils # BACKGROUND_COLOR="[225,225,225]" # matte_white # EXT="png" # NUM_WORKERS=-1 SOURCE_DIR="images/custom1024x1024/exemplars_male" OUTPUT_DIR="images/custom1024x1024_matte_white_background/exemplars_male" SEGMAP_DIR="segmaps/custom1024x1024/exemplars_male" MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils BACKGROUND_COLOR="[225,225,225]" # matte_white EXT="png" NUM_WORKERS=-1 # SOURCE_DIR="images/custom1024x1024/exemplars_female" # OUTPUT_DIR="images/custom1024x1024_matte_white_background/exemplars_female" # SEGMAP_DIR="segmaps/custom1024x1024/exemplars_female" # MASK_CLASSES="background" # i.e. "background cloth hat" refer src.utils.constant_utils # BACKGROUND_COLOR="[225,225,225]" # matte_white # EXT="png" # NUM_WORKERS=-1 # ===== 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.edit_images_by_class \ --source_dir "$SOURCE_DIR" \ --segmap_dir "$SEGMAP_DIR" \ --output_dir "$OUTPUT_DIR" \ --mask_classes $MASK_CLASSES \ --background_color "$BACKGROUND_COLOR" \ --ext "$EXT" \ --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"