magicmotion / trajectory_construction /image_mask_batch.sh
Qnancy's picture
Upload folder using huggingface_hub
ad44ad4 verified
#!/usr/bin/env bash
TOTAL=${1:-}
if ! [[ "$TOTAL" =~ ^[0-9]+$ ]]; then
echo "Usage: $0 TOTAL_SAMPLES"
exit 1
fi
conda activate /mnt/prev_nas/qhy/env/torch240
cd /mnt/prev_nas/qhy/MagicMotion/trajectory_construction/Grounded_SAM2
SCRIPT=/mnt/prev_nas/qhy/MagicMotion/trajectory_construction/image_mask_batch.py
PROMPTS_JSON=/mnt/prev_nas/qhy_1/datasets/unedit_image_prompts/genspace_prompts_vlm.json
DIR_JSONL=/mnt/5T_nas/cwl/wan/OmniGen2/data_configs/train/example/edit/qwen_direction_merged.jsonl
IMG_ROOT=/mnt/prev_nas/qhy_1/datasets/flux_gen_images
OUT_DIR=/mnt/prev_nas/qhy_1/datasets/flux_gen_images_masks
GPUS=(0 1 2 3 4 5 6 7)
N=${#GPUS[@]}
CHUNK=$(( (TOTAL + N - 1) / N ))
echo "TOTAL=${TOTAL}, N=${N}, CHUNK=${CHUNK}"
mkdir -p "${OUT_DIR}"
for i in "${!GPUS[@]}"; do
GPU=${GPUS[$i]}
START=$(( i * CHUNK ))
END=$(( (i + 1) * CHUNK ))
if [ "$END" -gt "$TOTAL" ]; then END="$TOTAL"; fi
if [ "$START" -ge "$TOTAL" ]; then continue; fi
echo "Launch GPU ${GPU}: [${START}, ${END})"
CUDA_VISIBLE_DEVICES=${GPU} \
python "$SCRIPT" \
--prompts_json "$PROMPTS_JSON" \
--dir_jsonl "$DIR_JSONL" \
--img_root "$IMG_ROOT" \
--img_ext ".png" \
--out_dir "$OUT_DIR" \
--start "$START" \
--end "$END" &
done
wait
echo "All done."