ChipYTY's picture
Add files using upload-large-folder tool
34a4bcb verified
#!/bin/bash
# MedSAM3 BraTS 分割完整流程脚本
# 配置路径
BRATS_RAW_DIR="/data/yty/brats2023/ASNR-MICCAI-BraTS2023-GLI-Challenge-TrainingData"
PROCESSED_DIR="/data/yty/brats23_sam3_processed"
OUTPUT_DIR="/data/yty/brats23_sam3_results"
SAM3_CHECKPOINT="/data/yty/sam3/sam3.pt"
# 处理参数
MODALITY=0 # 0=t1c, 1=t1n, 2=t2f, 3=t2w
TARGET_SIZE="512 512"
NUM_CASES=5 # 先测试5个病例,设为空处理所有
echo "============================================"
echo "MedSAM3 BraTS Segmentation Pipeline"
echo "============================================"
# Step 1: 预处理数据
echo ""
echo "Step 1: Preprocessing BraTS data..."
echo "--------------------------------------------"
if [ ! -z "$NUM_CASES" ]; then
NUM_CASES_ARG="--num_cases $NUM_CASES"
else
NUM_CASES_ARG=""
fi
python preprocess_brats.py \
--input_dir "$BRATS_RAW_DIR" \
--output_dir "$PROCESSED_DIR" \
--modality $MODALITY \
--target_size $TARGET_SIZE \
$NUM_CASES_ARG
if [ $? -ne 0 ]; then
echo "Error in preprocessing!"
exit 1
fi
# Step 2: SAM3 推理
echo ""
echo "Step 2: Running SAM3 inference..."
echo "--------------------------------------------"
python infer_brats_sam3.py \
--input_dir "$PROCESSED_DIR" \
--output_dir "$OUTPUT_DIR" \
--checkpoint "$SAM3_CHECKPOINT" \
--prompt_type box \
--visualize
if [ $? -ne 0 ]; then
echo "Error in inference!"
exit 1
fi
echo ""
echo "============================================"
echo "Pipeline completed!"
echo "Results saved to: $OUTPUT_DIR"
echo "============================================"