| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Check if any argument is provided. |
| 4 |
if [ $# -eq 0 ]; then |
| 5 |
echo "Usage: $0 <host_directory>" |
| 6 |
echo "Example: $0 ../dataset/" |
| 7 |
exit 1 |
| 8 |
fi |
| 9 |
|
| 10 |
# Check if local colmap:latest image exists (in case you ran build.sh), otherwise use official image |
| 11 |
if docker image inspect colmap:latest >/dev/null 2>&1; then |
| 12 |
echo "Using local COLMAP Docker image..." |
| 13 |
COLMAP_IMAGE="colmap:latest" |
| 14 |
else |
| 15 |
echo "Local COLMAP image not found, pulling official image..." |
| 16 |
docker pull colmap/colmap:latest |
| 17 |
COLMAP_IMAGE="colmap/colmap:latest" |
| 18 |
fi |
| 19 |
|
| 20 |
# Get absolute path |
| 21 |
HOST_DIR=$(realpath "$1") |
| 22 |
if [ ! -d "$HOST_DIR" ]; then |
| 23 |
echo "Error: Directory '$HOST_DIR' does not exist." |
| 24 |
exit 1 |
| 25 |
fi |
| 26 |
echo "Running COLMAP container with directory: $HOST_DIR" |
| 27 |
|
| 28 |
# --- Build Docker Arguments --- |
| 29 |
# Start with the base arguments. |
| 30 |
DOCKER_ARGS=( |
| 31 |
-it --rm |
| 32 |
-v "${HOST_DIR}:/working" |
| 33 |
-w /working |
| 34 |
) |
| 35 |
|
| 36 |
# --- GPU Detection and Configuration --- |
| 37 |
echo "Testing for GPU acceleration..." |
| 38 |
# A successful `nvidia-smi` call is the most reliable test. |
| 39 |
if docker run --rm --runtime=nvidia "${COLMAP_IMAGE}" nvidia-smi >/dev/null 2>&1; then |
| 40 |
echo "✅ GPU detected. Using --runtime=nvidia." |
| 41 |
DOCKER_ARGS+=( --runtime=nvidia ) |
| 42 |
else |
| 43 |
echo "⚠️ GPU not detected. Using CPU mode." |
| 44 |
fi |
| 45 |
|
| 46 |
# --- Execute the Container --- |
| 47 |
# Always start an interactive bash shell. |
| 48 |
echo "Starting interactive bash shell..." |
| 49 |
docker run "${DOCKER_ARGS[@]}" "${COLMAP_IMAGE}" bash |