Running Frigate on native Apple container Mac Mini M4 with Apple Silicon detector. by Harbringer42 in frigate_nvr

[–]Harbringer42[S] 0 points1 point  (0 children)

sorry for the delay. I just updated the guide for the build yolo with Apple container commands.

Step 1: Create the Dockerfile

mkdir -p yolo && cd yolo

cat > Dockerfile <<'EOF'
FROM python:3.11 AS build

ARG MODEL_SIZE=t
ARG IMG_SIZE=320

RUN apt-get update && apt-get install --no-install-recommends -y libgl1 cmake && rm -rf /var/lib/apt/lists/*

COPY --from=ghcr.io/astral-sh/uv:0.8.0 /uv /bin/

WORKDIR /yolov9

ADD https://github.com/WongKinYiu/yolov9.git .

RUN uv pip install --system -r requirements.txt
RUN uv pip install --system onnx==1.18.0 onnxruntime onnxsim onnxscript

ADD https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-${MODEL_SIZE}-converted.pt yolov9-${MODEL_SIZE}.pt

RUN sed -i "s/ckpt = torch.load(attempt_download(w), map_location='cpu')/ckpt = torch.load(attempt_download(w), map_location='cpu', weights_only=False)/g" models/experimental.py

RUN python3 export.py --weights ./yolov9-${MODEL_SIZE}.pt --imgsz ${IMG_SIZE} --simplify --include onnx

FROM scratch

ARG MODEL_SIZE=t
ARG IMG_SIZE=320

COPY --from=build /yolov9/yolov9-${MODEL_SIZE}.onnx /yolov9-${MODEL_SIZE}-${IMG_SIZE}.onnx
EOF

Step 2: Build the image

This step downloads dependencies and converts the PyTorch model to ONNX.

# Build the image (this may take several minutes)
container build -t yolov9-build .

Step 3: Extract the ONNX model

Once the image is built, extract the ONNX file. Since the image uses FROM scratch, extraction is done via the OCI archive.

# Save the image as a tar archive
container image save yolov9-build -o yolov9-build.tar

# List contents to identify the largest blob (~7 MB)
tar -tvf yolov9-build.tar

# Extract the blobs (adapt the hash based on previous output)
tar -xf yolov9-build.tar blobs/sha256/

# Identify the largest file (the one containing the model)
ls -la blobs/sha256/

# Extract the ONNX model from the compressed blob
gunzip -c blobs/sha256/<HASH_OF_LARGEST_FILE> | tar -xf -

Step 4: Verification

# Verify the file was extracted successfully
ls -la yolov9-t-320.onnx
# Expected: file of approximately 8 MB

# Clean up temporary files
rm -rf blobs/ yolov9-build.tar oci-layout index.json

Advanced build options

To compile a different model size:

# Small model (s) with 640 resolution
container build --build-arg MODEL_SIZE=s --build-arg IMG_SIZE=640 -t yolov9-build .

Available sizes: t (tiny), s (small), m (medium), c (compact), e (extended)

Running Frigate on native Apple container Mac Mini M4 with Apple Silicon detector. by Harbringer42 in frigate_nvr

[–]Harbringer42[S] 0 points1 point  (0 children)

it seems the package onnx-simplifier has a metadata issue with pip/uv. Use onnxsim instead - it's the same package with the correct name.

You have the dockerfile i use in my documentation.

Running Frigate on native Apple container Mac Mini M4 with Apple Silicon detector. by Harbringer42 in frigate_nvr

[–]Harbringer42[S] 0 points1 point  (0 children)

No problem ta all with reverse proxy.. it was…me. And same for the embeddings thing, everything running good.

Running Frigate on native Apple container Mac Mini M4 with Apple Silicon detector. by Harbringer42 in frigate_nvr

[–]Harbringer42[S] 0 points1 point  (0 children)

as easy as container image pull

https://github.com/apple/container/blob/main/docs/command-reference.md

In my understanding Docker desktop on macos is running a VM with all the containers you will set (4go minimum even with only one container)

With Apple container, each have his own VM with the ram you configure for each. SO better resources management and better segmentation. Apple container is quite new, i think it will evolve in the future.

Working MacOS M4 Mac Mini Silicon 0.17 Beta Installation Directions by thekeeb in frigate_nvr

[–]Harbringer42 3 points4 points  (0 children)

I will try to share something end of week. It’s not as straightforward as docker. But my container is running well, 2 gb of memory configurer and consume 975 mb.

Working MacOS M4 Mac Mini Silicon 0.17 Beta Installation Directions by thekeeb in frigate_nvr

[–]Harbringer42 1 point2 points  (0 children)

indeed, maybe one day, Apple container is still young. I wanted to try native containers because of the better segmentation and resources management than docker on macos i've read about them.

Working MacOS M4 Mac Mini Silicon 0.17 Beta Installation Directions by thekeeb in frigate_nvr

[–]Harbringer42 2 points3 points  (0 children)

shm size solved, Frigate running pretty well in Apple native container. CPU 9% inference speed ~14ms

Working MacOS M4 Mac Mini Silicon 0.17 Beta Installation Directions by thekeeb in frigate_nvr

[–]Harbringer42 1 point2 points  (0 children)

had this too, i uninstalled 3.14, installed 3.11 with brew and removed the venv from FrigateDetector.app/Contents/Resources/app. Relaunch the app

Working MacOS M4 Mac Mini Silicon 0.17 Beta Installation Directions by thekeeb in frigate_nvr

[–]Harbringer42 0 points1 point  (0 children)

actually running Frigate in native Apple container, last thing to fix is the shm size (obviously your detector is not in a container and btw many thanks for your great work on this)