From d3d85e5487580702cb4b3b5c6db8c188a5401cc8 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Thu, 21 Nov 2024 15:18:11 +0100 Subject: [PATCH] frigate: provide the tflite audio model --- pkgs/by-name/fr/frigate/package.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/fr/frigate/package.nix b/pkgs/by-name/fr/frigate/package.nix index 7ee4f6eba606f5..03229c25c5f95d 100644 --- a/pkgs/by-name/fr/frigate/package.nix +++ b/pkgs/by-name/fr/frigate/package.nix @@ -29,6 +29,12 @@ let }; }; + # Tensorflow audio model + tflite_audio_model = fetchurl { + url = "https://www.kaggle.com/api/v1/models/google/yamnet/tfLite/classification-tflite/1/download"; + hash = "sha256-G5cbITJ2AnOl+49dxQToZ4OyeFO7MTXVVa4G8eHjZfM="; + }; + # Tensorflow Lite models # https://github.com/blakeblackshear/frigate/blob/v0.13.0/docker/main/Dockerfile#L96-L97 tflite_cpu_model = fetchurl { @@ -76,10 +82,15 @@ python.pkgs.buildPythonApplication rec { substituteInPlace frigate/ptz/onvif.py \ --replace-fail dist-packages site-packages + # provide default paths for models and maps that are shipped with frigate substituteInPlace frigate/config.py \ --replace-fail "/cpu_model.tflite" "${tflite_cpu_model}" \ --replace-fail "/edgetpu_model.tflite" "${tflite_edgetpu_model}" + substituteInPlace frigate/events/audio.py \ + --replace-fail "/cpu_audio_model.tflite" "${placeholder "out"}/share/frigate/cpu_audio_model.tflite" \ + --replace-fail "/audio-labelmap.txt" "${placeholder "out"}/share/frigate/audio-labelmap.txt" + substituteInPlace frigate/test/test_config.py \ --replace-fail "(MODEL_CACHE_DIR" "('/build/model_cache'" \ --replace-fail "/config/model_cache" "/build/model_cache" @@ -131,7 +142,10 @@ python.pkgs.buildPythonApplication rec { cp -R frigate/* $out/${python.sitePackages}/frigate/ mkdir -p $out/share/frigate - cp -R {migrations,labelmap.txt} $out/share/frigate/ + cp -R {migrations,labelmap.txt,audio-labelmap.txt} $out/share/frigate/ + + tar --extract --gzip --file ${tflite_audio_model} + cp --no-preserve=mode ./1.tflite $out/share/frigate/cpu_audio_model.tflite cp --no-preserve=mode ${openvino_model} $out/share/frigate/coco_91cl_bkgr.txt sed -i 's/truck/car/g' $out/share/frigate/coco_91cl_bkgr.txt