Last active
October 24, 2025 07:15
-
-
Save orian/c51d1cf8c09885e2fa562cfb550cc467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Multi-stage Dockerfile for Darknet (CPU-only) | |
| # Compiles Darknet from Codeberg repository for object detection | |
| # docker build -f Dockerfile.darknet --tag darknet-cpu:latest | |
| # Build stage | |
| FROM ubuntu:24.04 AS builder | |
| # Prevent interactive prompts during package installation | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # Install build dependencies | |
| # Ubuntu 24.04 ships with CMake 3.28+, which meets Darknet's requirements | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| git \ | |
| cmake \ | |
| libopencv-dev \ | |
| libopenblas-dev \ | |
| ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Clone Darknet from Codeberg | |
| WORKDIR /build | |
| RUN git clone https://codeberg.org/CCodeRun/darknet.git darknet | |
| # Build Darknet with CMake (CPU-only with OpenBLAS, optimized) | |
| WORKDIR /build/darknet | |
| RUN cmake -B build \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DENABLE_CUDA=OFF \ | |
| -DENABLE_CUDNN=OFF \ | |
| -DENABLE_OPENBLAS=ON \ | |
| -DCMAKE_INSTALL_PREFIX=/usr/local \ | |
| && cmake --build build --parallel $(nproc) \ | |
| && cmake --install build | |
| # Runtime stage | |
| FROM ubuntu:24.04 | |
| # Prevent interactive prompts | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # Install runtime dependencies (OpenCV + OpenBLAS libraries) | |
| # Ubuntu 24.04 ships with OpenCV 4.6 | |
| # Install libopencv-dev to get all OpenCV runtime libraries | |
| # Install libopenblas0 for optimized linear algebra operations | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libopencv-dev \ | |
| libopenblas0 \ | |
| ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy Darknet installation from builder | |
| COPY --from=builder /usr/local/bin/darknet /usr/local/bin/darknet | |
| COPY --from=builder /usr/local/lib/libdarknet* /usr/local/lib/ | |
| COPY --from=builder /usr/local/include/darknet*.h* /usr/local/include/ | |
| COPY --from=builder /opt/darknet/cfg /usr/local/share/darknet/cfg | |
| # Copy example binaries from src-examples | |
| COPY --from=builder /build/darknet/build/src-examples/darknet_* /usr/local/bin/ | |
| # Update library cache | |
| RUN ldconfig | |
| # Create non-root user for running darknet | |
| RUN groupadd -r darknet && useradd -r -g darknet darknet | |
| # Create workspace directory | |
| RUN mkdir -p /workspace /weights /output && \ | |
| chown -R darknet:darknet /workspace /weights /output | |
| # Switch to non-root user | |
| USER darknet | |
| # Set working directory | |
| WORKDIR /workspace | |
| # Volume mounts for data | |
| VOLUME ["/workspace", "/weights", "/output"] | |
| # Default command shows help | |
| ENTRYPOINT ["darknet"] | |
| CMD ["--help"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| MODEL_DIR=$(pwd)/models/r-people/people-r-people_2025-05-05 | |
| docker run --rm \ | |
| -v $MODEL_DIR:/models:ro \ | |
| -v $MODEL_DIR/sample_images:/input:ro \ | |
| -v $(pwd)/output:/output \ | |
| -w /output --entrypoint darknet_01_inference_images \ | |
| darknet-cpu:latest \ | |
| /models/people-r-people.cfg /models/people-r-people.weights /models/people-r-people.names /input/mcmurdo_station.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment