|
|
#!/usr/bin/env bash |
|
|
set -euo pipefail |
|
|
|
|
|
echo "postBuild: starting detectron2 setup" |
|
|
python -V || true |
|
|
pip --version || true |
|
|
|
|
|
|
|
|
python - <<'PY' || true |
|
|
import torch, platform, sys |
|
|
print("Torch:", torch.__version__) |
|
|
print("CUDA available:", torch.cuda.is_available()) |
|
|
print("torch.version.cuda:", getattr(torch.version, "cuda", None)) |
|
|
print("Python:", sys.version.split()[0]) |
|
|
print("Platform:", platform.platform()) |
|
|
PY |
|
|
|
|
|
|
|
|
PYTORCH_MM="$(python - <<'PY' |
|
|
import torch |
|
|
v = torch.__version__.split('+')[0].split('.') |
|
|
print(f"{v[0]}.{v[1]}") |
|
|
PY |
|
|
)" |
|
|
CUDA_TAG="$(python - <<'PY' |
|
|
import torch |
|
|
cv = getattr(torch.version, "cuda", None) |
|
|
print(("cu"+cv.replace(".","")) if cv else "cpu") |
|
|
PY |
|
|
)" |
|
|
|
|
|
WHEEL_URL="https://dl.fbaipublicfiles.com/detectron2/wheels/${CUDA_TAG}/torch${PYTORCH_MM}/index.html" |
|
|
echo "Attempting detectron2 wheel from: ${WHEEL_URL}" |
|
|
|
|
|
if pip install --no-cache-dir "detectron2" -f "${WHEEL_URL}"; then |
|
|
echo "detectron2 installed from prebuilt wheel" |
|
|
else |
|
|
echo "Prebuilt wheel not available. Building detectron2 from source (CPU-only) ..." |
|
|
export FORCE_CUDA=0 |
|
|
pip install --no-cache-dir --no-build-isolation "git+https://github.com/facebookresearch/detectron2.git@fd27788985af0f4ca800bca563acdb700bb890e2" |
|
|
fi |
|
|
|
|
|
|
|
|
python - <<'PY' |
|
|
import importlib |
|
|
spec = importlib.util.find_spec("detectron2") |
|
|
if spec is None: |
|
|
raise SystemExit("detectron2 not found after installation") |
|
|
import detectron2 |
|
|
print("detectron2 installed. Version:", getattr(detectron2, "__version__", "unknown")) |
|
|
PY |
|
|
|
|
|
echo "postBuild: detectron2 setup completed" |
|
|
|
|
|
set -e |
|
|
|
|
|
echo "[postBuild] Prepare build tools..." |
|
|
python -m pip install -U pip setuptools wheel ninja |
|
|
|
|
|
echo "[postBuild] Installing vendored detectron2 from MaskClustering/third_party/detectron2 ..." |
|
|
|
|
|
|
|
|
export MAX_JOBS=${MAX_JOBS:-1} |
|
|
python -m pip install --no-build-isolation -e MaskClustering/third_party/detectron2 |
|
|
|
|
|
|