.PHONY: install train test lint format clean docs preprocess run help # EMCAD 项目 Makefile # 提供常用命令的快捷入口 # 安装依赖 install: pip install -r requirements.txt pip install -e . # 运行训练 (Synapse 数据集) train: export CUDA_VISIBLE_DEVICES=0 python scripts/train_synapse.py --cfg configs/default.yaml # 运行训练 (ACDC 数据集) train-acdc: export CUDA_VISIBLE_DATA_DEVICES=0 python scripts/train_acdc.py --cfg configs/default.yaml # 运行测试 test: python -m pytest tests/ -v --tb=short # 运行特定测试文件 test-synapse: python -m pytest tests/test_synapse.py -v --tb=short # 代码检查 (ruff) lint: ruff check src/ tests/ ruff check scripts/ # 代码格式化 (ruff) format: ruff format src/ tests/ scripts/ isort src/ tests/ scripts/ # 类型检查 (mypy, 如果安装了的话) typecheck: mypy src/ --ignore-missing-imports || echo "mypy not installed, skipping type check" # 完整代码质量检查 check: lint format typecheck # 数据预处理 (Synapse) preprocess-synapse: python src/utils/preprocess_synapse_data.py # 数据预处理 (ACDC) preprocess-acdc: python src/utils/preprocess_acdc_data.py # 清理临时文件 clean: find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true find . -type f -name "*.pyc" -delete 2>/dev/null || true find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true rm -rf .coverage htmlcov/ .mypy_cache/ .ruff_cache/ # 清理实验输出 clean-experiments: rm -rf experiments/ logs/ *.log # 清理所有生成的文件 clean-all: clean clean-experiments # 构建文档 docs: cd docs && make html || sphinx-build -b html docs/source docs/build # 查看文档 docs-serve: cd docs && make livehtml || sphinx-autobuild docs/source docs/build --host 0.0.0.0 --port 8000 # 运行示例推理 run-inference: python scripts/inference.py --cfg configs/default.yaml --checkpoint experiments/latest.pth --input input.png # 创建实验目录结构 setup-dirs: mkdir -p experiments/ logs/ model_pth/ pretrained_pth/ # 显示帮助信息 help: @echo "EMCAD 项目 Makefile 命令:" @echo "" @echo " install - 安装项目依赖" @echo " train - 运行 Synapse 数据集训练" @echo " train-acdc - 运行 ACDC 数据集训练" @echo " test - 运行所有测试" @echo " test-synapse - 运行 Synapse 测试" @echo " lint - 代码检查 (ruff)" @echo " format - 代码格式化 (ruff, isort)" @echo " typecheck - 类型检查 (mypy)" @echo " check - 完整代码质量检查" @echo " preprocess-synapse - 预处理 Synapse 数据" @echo " preprocess-acdc - 预处理 ACDC 数据" @echo " clean - 清理 Python 缓存文件" @echo " clean-experiments - 清理实验输出" @echo " clean-all - 清理所有生成的文件" @echo " docs - 构建文档" @echo " docs-serve - 启动文档预览服务器" @echo " run-inference - 运行示例推理" @echo " setup-dirs - 创建目录结构" @echo " help - 显示此帮助信息"