root_dir=/output_folder_contains_subdirs
subdirs=(`ls $root_dir`)
CUDA_DEVICES=(0 1 2 3) # CUDA devices to use
SCRIPT=./metric.py
# CUDA_VISIBLE_DEVICES=$device python $SCRIPT --input_dir $root_dir --output_json $root_dir_aesthetic.json
CUR_DEVICE=0
for subdir in ${subdirs[@]}; do
    #check if directory exists
    if [ ! -d $root_dir/$subdir ]; then
        continue
    fi
    root_dir_aesthetic=$root_dir/$subdir/aesthetic
    device=${CUDA_DEVICES[$CUR_DEVICE]}
    echo "CUDA_VISIBLE_DEVICES=$device python3.11 $SCRIPT --input_dir $root_dir/$subdir --output_json $root_dir_aesthetic.json"
    CUDA_VISIBLE_DEVICES=$device python3.11 $SCRIPT --input_dir $root_dir/$subdir --output_json $root_dir_aesthetic.json &
    CUR_DEVICE=$((CUR_DEVICE+1))
    if [ $CUR_DEVICE -eq 4 ]; then
        CUR_DEVICE=0
    fi
done
wait
