Skip to content

Commit

Permalink
Merge branch 'blakeblackshear:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
weitheng authored Nov 9, 2024
2 parents 2840f78 + 580f351 commit 5eb6530
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 140 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
# count: 1
# capabilities: [gpu]
environment:
YOLO_MODELS: yolov7-320
YOLO_MODELS: ""
devices:
- /dev/bus/usb:/dev/bus/usb
# - /dev/dri:/dev/dri # for intel hwaccel, needs to be updated for your hardware
Expand Down
2 changes: 1 addition & 1 deletion docker/tensorrt/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
COPY --from=trt-deps /usr/local/src/tensorrt_demos /usr/local/src/tensorrt_demos
COPY docker/tensorrt/detector/rootfs/ /
ENV YOLO_MODELS="yolov7-320"
ENV YOLO_MODELS=""

HEALTHCHECK --start-period=600s --start-interval=5s --interval=15s --timeout=5s --retries=3 \
CMD curl --fail --silent --show-error http://127.0.0.1:5000/api/version || exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ FIRST_MODEL=true
MODEL_DOWNLOAD=""
MODEL_CONVERT=""

if [ -z "$YOLO_MODELS"]; then
echo "tensorrt model preparation disabled"
exit 0
fi

for model in ${YOLO_MODELS//,/ }
do
# Remove old link in case path/version changed
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/configuration/genai.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ id: genai
title: Generative AI
---

Generative AI can be used to automatically generate descriptive text based on the thumbnails of your tracked objects. This helps with [Semantic Search](/configuration/semantic_search) in Frigate to provide more context about your tracked objects.
Generative AI can be used to automatically generate descriptive text based on the thumbnails of your tracked objects. This helps with [Semantic Search](/configuration/semantic_search) in Frigate to provide more context about your tracked objects. Descriptions are accessed via the _Explore_ view in the Frigate UI by clicking on a tracked object's thumbnail.

Semantic Search must be enabled to use Generative AI. Descriptions are accessed via the _Explore_ view in the Frigate UI by clicking on a tracked object's thumbnail.
:::info

Semantic Search must be enabled to use Generative AI.

:::

## Configuration

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/configuration/object_detectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ The model used for TensorRT must be preprocessed on the same hardware platform t

The Frigate image will generate model files during startup if the specified model is not found. Processed models are stored in the `/config/model_cache` folder. Typically the `/config` path is mapped to a directory on the host already and the `model_cache` does not need to be mapped separately unless the user wants to store it in a different location on the host.

By default, the `yolov7-320` model will be generated, but this can be overridden by specifying the `YOLO_MODELS` environment variable in Docker. One or more models may be listed in a comma-separated format, and each one will be generated. To select no model generation, set the variable to an empty string, `YOLO_MODELS=""`. Models will only be generated if the corresponding `{model}.trt` file is not present in the `model_cache` folder, so you can force a model to be regenerated by deleting it from your Frigate data folder.
By default, no models will be generated, but this can be overridden by specifying the `YOLO_MODELS` environment variable in Docker. One or more models may be listed in a comma-separated format, and each one will be generated. Models will only be generated if the corresponding `{model}.trt` file is not present in the `model_cache` folder, so you can force a model to be regenerated by deleting it from your Frigate data folder.

If you have a Jetson device with DLAs (Xavier or Orin), you can generate a model that will run on the DLA by appending `-dla` to your model name, e.g. specify `YOLO_MODELS=yolov7-320-dla`. The model will run on DLA0 (Frigate does not currently support DLA1). DLA-incompatible layers will fall back to running on the GPU.

Expand Down Expand Up @@ -264,7 +264,7 @@ An example `docker-compose.yml` fragment that converts the `yolov4-608` and `yol
```yml
frigate:
environment:
- YOLO_MODELS=yolov4-608,yolov7x-640
- YOLO_MODELS=yolov7-320,yolov7x-640
- USE_FP16=false
```

Expand Down
4 changes: 3 additions & 1 deletion frigate/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,9 +1017,11 @@ def regenerate_description(
status_code=404,
)

camera_config = request.app.frigate_config.cameras[event.camera]

if (
request.app.frigate_config.semantic_search.enabled
and request.app.frigate_config.genai.enabled
and camera_config.genai.enabled
):
request.app.event_metadata_updater.publish((event.id, params.source))

Expand Down
14 changes: 9 additions & 5 deletions frigate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
from frigate.record.export import migrate_exports
from frigate.record.record import manage_recordings
from frigate.review.review import manage_review_segments
from frigate.service_manager import ServiceManager
from frigate.stats.emitter import StatsEmitter
from frigate.stats.util import stats_init
from frigate.storage import StorageMaintainer
Expand All @@ -79,6 +78,7 @@

class FrigateApp:
def __init__(self, config: FrigateConfig) -> None:
self.audio_process: Optional[mp.Process] = None
self.stop_event: MpEvent = mp.Event()
self.detection_queue: Queue = mp.Queue()
self.detectors: dict[str, ObjectDetectProcess] = {}
Expand Down Expand Up @@ -449,8 +449,9 @@ def start_audio_processor(self) -> None:
]

if audio_cameras:
proc = AudioProcessor(audio_cameras, self.camera_metrics).start(wait=True)
self.processes["audio_detector"] = proc.pid or 0
self.audio_process = AudioProcessor(audio_cameras, self.camera_metrics)
self.audio_process.start()
self.processes["audio_detector"] = self.audio_process.pid or 0

def start_timeline_processor(self) -> None:
self.timeline_processor = TimelineProcessor(
Expand Down Expand Up @@ -641,6 +642,11 @@ def stop(self) -> None:
ReviewSegment.end_time == None
).execute()

# stop the audio process
if self.audio_process:
self.audio_process.terminate()
self.audio_process.join()

# ensure the capture processes are done
for camera, metrics in self.camera_metrics.items():
capture_process = metrics.capture_process
Expand Down Expand Up @@ -709,6 +715,4 @@ def stop(self) -> None:
shm.close()
shm.unlink()

ServiceManager.current().shutdown(wait=True)

os._exit(os.EX_OK)
6 changes: 3 additions & 3 deletions frigate/events/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
import requests

import frigate.util as util
from frigate.camera import CameraMetrics
from frigate.comms.config_updater import ConfigSubscriber
from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum
Expand All @@ -25,7 +26,6 @@
from frigate.ffmpeg_presets import parse_preset_input
from frigate.log import LogPipe
from frigate.object_detection import load_labels
from frigate.service_manager import ServiceProcess
from frigate.util.builtin import get_ffmpeg_arg_list
from frigate.video import start_or_restart_ffmpeg, stop_ffmpeg

Expand Down Expand Up @@ -63,15 +63,15 @@ def get_ffmpeg_command(ffmpeg: FfmpegConfig) -> list[str]:
)


class AudioProcessor(ServiceProcess):
class AudioProcessor(util.Process):
name = "frigate.audio_manager"

def __init__(
self,
cameras: list[CameraConfig],
camera_metrics: dict[str, CameraMetrics],
):
super().__init__()
super().__init__(name="frigate.audio_manager", daemon=True)

self.camera_metrics = camera_metrics
self.cameras = cameras
Expand Down
9 changes: 4 additions & 5 deletions frigate/genai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ def _send(self, prompt: str, images: list[bytes]) -> Optional[str]:

def get_genai_client(genai_config: GenAIConfig) -> Optional[GenAIClient]:
"""Get the GenAI client."""
if genai_config.enabled:
load_providers()
provider = PROVIDERS.get(genai_config.provider)
if provider:
return provider(genai_config)
load_providers()
provider = PROVIDERS.get(genai_config.provider)
if provider:
return provider(genai_config)
return None


Expand Down
2 changes: 1 addition & 1 deletion frigate/output/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
# write a PREVIEW at fps and 1 key frame per clip
self.ffmpeg_cmd = parse_preset_hardware_acceleration_encode(
config.ffmpeg.ffmpeg_path,
config.ffmpeg.hwaccel_args,
"default",
input="-f concat -y -protocol_whitelist pipe,file -safe 0 -threads 1 -i /dev/stdin",
output=f"-threads 1 -g {PREVIEW_KEYFRAME_INTERVAL} -bf 0 -b:v {PREVIEW_QUALITY_BIT_RATES[self.config.record.preview.quality]} {FPS_VFR_PARAM} -movflags +faststart -pix_fmt yuv420p {self.path}",
type=EncodeTypeEnum.preview,
Expand Down
8 changes: 7 additions & 1 deletion web/src/api/ws.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ function useValue(): useValueReturn {
...prevState,
...cameraStates,
}));
setHasCameraState(true);

if (Object.keys(cameraStates).length > 0) {
setHasCameraState(true);
}
// we only want this to run initially when the config is loaded
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [wsState]);
Expand All @@ -93,6 +96,9 @@ function useValue(): useValueReturn {
retain: false,
});
},
onClose: () => {
setHasCameraState(false);
},
shouldReconnect: () => true,
retryOnError: true,
});
Expand Down
Loading

0 comments on commit 5eb6530

Please sign in to comment.