mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 09:45:22 +03:00
Update detect to normalize input tensor using model input type
This commit is contained in:
parent
c01507081e
commit
de251c2c21
@ -166,6 +166,7 @@ To generate the model files, create a new folder to save the models, download th
|
||||
```bash
|
||||
mkdir trt-models
|
||||
wget https://github.com/blakeblackshear/frigate/raw/master/docker/tensorrt_models.sh
|
||||
chmod +x tensorrt_models.sh
|
||||
docker run --gpus=all --rm -it -v `pwd`/trt-models:/tensorrt_models -v `pwd`/tensorrt_models.sh:/tensorrt_models.sh nvcr.io/nvidia/tensorrt:22.07-py3 /tensorrt_models.sh
|
||||
```
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import numpy as np
|
||||
|
||||
try:
|
||||
import tensorrt as trt
|
||||
from cuda import cuda, cudart
|
||||
from cuda import cuda
|
||||
|
||||
TRT_SUPPORT = True
|
||||
except ModuleNotFoundError as e:
|
||||
@ -72,7 +72,7 @@ class HostDeviceMem(object):
|
||||
|
||||
class TensorRtDetector(DetectionApi):
|
||||
type_key = DETECTOR_KEY
|
||||
# class LocalObjectDetector(ObjectDetector):
|
||||
|
||||
def _load_engine(self, model_path):
|
||||
try:
|
||||
ctypes.cdll.LoadLibrary(
|
||||
@ -100,9 +100,15 @@ class TensorRtDetector(DetectionApi):
|
||||
assert self.engine.binding_is_input(binding)
|
||||
binding_dims = self.engine.get_binding_shape(binding)
|
||||
if len(binding_dims) == 4:
|
||||
return tuple(binding_dims[2:])
|
||||
return (
|
||||
tuple(binding_dims[2:]),
|
||||
trt.nptype(self.engine.get_binding_dtype(binding)),
|
||||
)
|
||||
elif len(binding_dims) == 3:
|
||||
return tuple(binding_dims[1:])
|
||||
return (
|
||||
tuple(binding_dims[1:]),
|
||||
trt.nptype(self.engine.get_binding_dtype(binding)),
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
"bad dims of binding %s: %s" % (binding, str(binding_dims))
|
||||
@ -249,10 +255,13 @@ class TensorRtDetector(DetectionApi):
|
||||
# 2..5 - a value between 0 and 1 of the box: [top, left, bottom, right]
|
||||
|
||||
# normalize
|
||||
tensor_input = tensor_input.astype(np.float32)
|
||||
if self.input_shape[-1] != trt.int8:
|
||||
tensor_input = tensor_input.astype(self.input_shape[-1])
|
||||
tensor_input /= 255.0
|
||||
|
||||
self.inputs[0].host = np.ascontiguousarray(tensor_input.astype(np.float32))
|
||||
self.inputs[0].host = np.ascontiguousarray(
|
||||
tensor_input.astype(self.input_shape[-1])
|
||||
)
|
||||
trt_outputs = self._do_inference()
|
||||
|
||||
raw_detections = self._postprocess_yolo(trt_outputs, self.conf_th)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user