File size: 3,660 Bytes
452723c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e960d6
 
 
 
 
 
 
 
f91b4c8
 
 
 
 
 
 
 
 
 
 
452723c
 
 
 
 
f91b4c8
 
 
 
 
 
 
 
452723c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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"