mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-08 06:15:43 +03:00
Compare commits
No commits in common. "170738bd5b239b85a94ce9e57fcbb1e81d5b7364" and "5bda917b3179773ba885794e93d4b4bf78139222" have entirely different histories.
170738bd5b
...
5bda917b31
25
.github/workflows/ci.yml
vendored
25
.github/workflows/ci.yml
vendored
@ -173,31 +173,6 @@ jobs:
|
|||||||
set: |
|
set: |
|
||||||
rk.tags=${{ steps.setup.outputs.image-name }}-rk
|
rk.tags=${{ steps.setup.outputs.image-name }}-rk
|
||||||
*.cache-from=type=gha
|
*.cache-from=type=gha
|
||||||
synaptics_build:
|
|
||||||
runs-on: ubuntu-22.04-arm
|
|
||||||
name: Synaptics Build
|
|
||||||
needs:
|
|
||||||
- arm64_build
|
|
||||||
steps:
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v5
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Set up QEMU and Buildx
|
|
||||||
id: setup
|
|
||||||
uses: ./.github/actions/setup
|
|
||||||
with:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- name: Build and push Synaptics build
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
source: .
|
|
||||||
push: true
|
|
||||||
targets: synaptics
|
|
||||||
files: docker/synaptics/synaptics.hcl
|
|
||||||
set: |
|
|
||||||
synaptics.tags=${{ steps.setup.outputs.image-name }}-synaptics
|
|
||||||
*.cache-from=type=gha
|
|
||||||
# The majority of users running arm64 are rpi users, so the rpi
|
# The majority of users running arm64 are rpi users, so the rpi
|
||||||
# build should be the primary arm64 image
|
# build should be the primary arm64 image
|
||||||
assemble_default_build:
|
assemble_default_build:
|
||||||
|
|||||||
@ -1,19 +1,16 @@
|
|||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from synap import Network
|
from synap import Network
|
||||||
from synap.postprocessor import Detector
|
from synap.types import Shape, Layout
|
||||||
from synap.preprocessor import Preprocessor
|
from synap.preprocessor import Preprocessor
|
||||||
from synap.types import Layout, Shape
|
from synap.postprocessor import Detector
|
||||||
from typing_extensions import Literal
|
|
||||||
|
|
||||||
from frigate.detectors.detection_api import DetectionApi
|
from frigate.detectors.detection_api import DetectionApi
|
||||||
from frigate.detectors.detector_config import (
|
from frigate.detectors.detector_config import BaseDetectorConfig, ModelTypeEnum, InputTensorEnum
|
||||||
BaseDetectorConfig,
|
|
||||||
InputTensorEnum,
|
|
||||||
ModelTypeEnum,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -23,7 +20,6 @@ DETECTOR_KEY = "synaptics"
|
|||||||
class SynapDetectorConfig(BaseDetectorConfig):
|
class SynapDetectorConfig(BaseDetectorConfig):
|
||||||
type: Literal[DETECTOR_KEY]
|
type: Literal[DETECTOR_KEY]
|
||||||
|
|
||||||
|
|
||||||
class SynapDetector(DetectionApi):
|
class SynapDetector(DetectionApi):
|
||||||
type_key = DETECTOR_KEY
|
type_key = DETECTOR_KEY
|
||||||
|
|
||||||
@ -41,7 +37,7 @@ class SynapDetector(DetectionApi):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to init Synap NPU: {e}")
|
logger.error(f"Failed to init Synap NPU: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
self.width = detector_config.model.width
|
self.width = detector_config.model.width
|
||||||
self.height = detector_config.model.height
|
self.height = detector_config.model.height
|
||||||
self.model_type = detector_config.model.model_type
|
self.model_type = detector_config.model.model_type
|
||||||
@ -56,28 +52,28 @@ class SynapDetector(DetectionApi):
|
|||||||
def detect_raw(self, tensor_input: np.ndarray):
|
def detect_raw(self, tensor_input: np.ndarray):
|
||||||
# It has only been testing for pre-converted mobilenet80 .tflite -> .synap model currently
|
# It has only been testing for pre-converted mobilenet80 .tflite -> .synap model currently
|
||||||
layout = Layout.nhwc # default layout
|
layout = Layout.nhwc # default layout
|
||||||
detections = np.zeros((20, 6), np.float32)
|
|
||||||
|
|
||||||
if self.input_tensor_layout == InputTensorEnum.nhwc:
|
if self.input_tensor_layout == InputTensorEnum.nhwc:
|
||||||
layout = Layout.nhwc
|
layout = Layout.nhwc
|
||||||
|
|
||||||
postprocess_data = self.preprocessor.assign(
|
postprocess_data = self.preprocessor.assign(self.network.inputs, tensor_input, Shape(tensor_input.shape), layout)
|
||||||
self.network.inputs, tensor_input, Shape(tensor_input.shape), layout
|
|
||||||
)
|
|
||||||
output_tensor_obj = self.network.predict()
|
output_tensor_obj = self.network.predict()
|
||||||
output = self.detector.process(output_tensor_obj, postprocess_data)
|
output = self.detector.process(output_tensor_obj, postprocess_data)
|
||||||
|
|
||||||
if self.model_type == ModelTypeEnum.ssd:
|
if self.model_type == ModelTypeEnum.ssd:
|
||||||
|
detections = np.zeros((20, 6), np.float32)
|
||||||
|
|
||||||
for i, item in enumerate(output.items):
|
for i, item in enumerate(output.items):
|
||||||
if i == 20:
|
if i == 20:
|
||||||
break
|
break
|
||||||
|
|
||||||
bb = item.bounding_box
|
bb = item.bounding_box
|
||||||
|
|
||||||
# Convert corner coordinates to normalized [0,1] range
|
# Convert corner coordinates to normalized [0,1] range
|
||||||
x1 = bb.origin.x / self.width # Top-left X
|
x1 = bb.origin.x / self.width # Top-left X
|
||||||
y1 = bb.origin.y / self.height # Top-left Y
|
y1 = bb.origin.y / self.height # Top-left Y
|
||||||
x2 = (bb.origin.x + bb.size.x) / self.width # Bottom-right X
|
x2 = (bb.origin.x + bb.size.x) / self.width # Bottom-right X
|
||||||
y2 = (bb.origin.y + bb.size.y) / self.height # Bottom-right Y
|
y2 = (bb.origin.y + bb.size.y) / self.height # Bottom-right Y
|
||||||
|
|
||||||
detections[i] = [
|
detections[i] = [
|
||||||
item.class_index,
|
item.class_index,
|
||||||
float(item.confidence),
|
float(item.confidence),
|
||||||
@ -86,6 +82,9 @@ class SynapDetector(DetectionApi):
|
|||||||
y2,
|
y2,
|
||||||
x2,
|
x2,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
return detections
|
||||||
else:
|
else:
|
||||||
logger.error(f"Unsupported model type: {self.model_type}")
|
print(f"Unsupported model type: {self.model_type}")
|
||||||
return detections
|
return np.zeros((20, 6), np.float32)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user