2023-05-29 05:31:17 -05:00
|
|
|
import datetime
|
2020-03-01 07:16:56 -06:00
|
|
|
import multiprocessing as mp
|
2023-05-29 05:31:17 -05:00
|
|
|
from statistics import mean
|
|
|
|
|
2019-06-04 21:38:41 -05:00
|
|
|
import numpy as np
|
2023-05-29 05:31:17 -05:00
|
|
|
|
2022-11-03 21:23:09 -05:00
|
|
|
from frigate.config import DetectorTypeEnum
|
|
|
|
from frigate.object_detection import (
|
|
|
|
ObjectDetectProcess,
|
|
|
|
RemoteObjectDetector,
|
|
|
|
load_labels,
|
|
|
|
)
|
2019-06-04 21:38:41 -05:00
|
|
|
|
2022-11-03 21:23:09 -05:00
|
|
|
my_frame = np.expand_dims(np.full((300, 300, 3), 1, np.uint8), axis=0)
|
|
|
|
labels = load_labels("/labelmap.txt")
|
2019-06-04 21:38:41 -05:00
|
|
|
|
2020-03-01 07:16:56 -06:00
|
|
|
######
|
|
|
|
# Minimal same process runner
|
|
|
|
######
|
2020-09-24 06:58:23 -05:00
|
|
|
# object_detector = LocalObjectDetector()
|
2020-03-01 07:16:56 -06:00
|
|
|
# tensor_input = np.expand_dims(np.full((300,300,3), 0, np.uint8), axis=0)
|
2019-06-04 21:38:41 -05:00
|
|
|
|
2020-03-01 07:16:56 -06:00
|
|
|
# start = datetime.datetime.now().timestamp()
|
2019-06-04 21:38:41 -05:00
|
|
|
|
2020-03-01 07:16:56 -06:00
|
|
|
# frame_times = []
|
|
|
|
# for x in range(0, 1000):
|
|
|
|
# start_frame = datetime.datetime.now().timestamp()
|
2019-06-04 21:38:41 -05:00
|
|
|
|
2020-03-01 07:16:56 -06:00
|
|
|
# tensor_input[:] = my_frame
|
|
|
|
# detections = object_detector.detect_raw(tensor_input)
|
|
|
|
# parsed_detections = []
|
|
|
|
# for d in detections:
|
|
|
|
# if d[1] < 0.4:
|
|
|
|
# break
|
|
|
|
# parsed_detections.append((
|
|
|
|
# labels[int(d[0])],
|
|
|
|
# float(d[1]),
|
|
|
|
# (d[2], d[3], d[4], d[5])
|
|
|
|
# ))
|
|
|
|
# frame_times.append(datetime.datetime.now().timestamp()-start_frame)
|
|
|
|
|
|
|
|
# duration = datetime.datetime.now().timestamp()-start
|
|
|
|
# print(f"Processed for {duration:.2f} seconds.")
|
|
|
|
# print(f"Average frame processing time: {mean(frame_times)*1000:.2f}ms")
|
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
|
2020-09-24 06:58:23 -05:00
|
|
|
def start(id, num_detections, detection_queue, event):
|
2022-11-03 21:23:09 -05:00
|
|
|
object_detector = RemoteObjectDetector(
|
|
|
|
str(id), "/labelmap.txt", detection_queue, event
|
|
|
|
)
|
|
|
|
start = datetime.datetime.now().timestamp()
|
2020-03-01 07:16:56 -06:00
|
|
|
|
2022-11-03 21:23:09 -05:00
|
|
|
frame_times = []
|
|
|
|
for x in range(0, num_detections):
|
|
|
|
start_frame = datetime.datetime.now().timestamp()
|
2023-05-29 05:31:17 -05:00
|
|
|
object_detector.detect(my_frame)
|
2022-11-03 21:23:09 -05:00
|
|
|
frame_times.append(datetime.datetime.now().timestamp() - start_frame)
|
|
|
|
|
|
|
|
duration = datetime.datetime.now().timestamp() - start
|
|
|
|
object_detector.cleanup()
|
|
|
|
print(f"{id} - Processed for {duration:.2f} seconds.")
|
|
|
|
print(f"{id} - FPS: {object_detector.fps.eps():.2f}")
|
|
|
|
print(f"{id} - Average frame processing time: {mean(frame_times)*1000:.2f}ms")
|
2020-03-01 07:16:56 -06:00
|
|
|
|
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
######
|
|
|
|
# Separate process runner
|
|
|
|
######
|
|
|
|
# event = mp.Event()
|
|
|
|
# detection_queue = mp.Queue()
|
|
|
|
# edgetpu_process = EdgeTPUProcess(detection_queue, {'1': event}, 'usb:0')
|
2020-03-01 07:16:56 -06:00
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
# start(1, 1000, edgetpu_process.detection_queue, event)
|
|
|
|
# print(f"Average raw inference speed: {edgetpu_process.avg_inference_speed.value*1000:.2f}ms")
|
2020-03-01 07:16:56 -06:00
|
|
|
|
|
|
|
####
|
|
|
|
# Multiple camera processes
|
|
|
|
####
|
2020-10-10 06:57:43 -05:00
|
|
|
camera_processes = []
|
2020-03-01 07:16:56 -06:00
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
events = {}
|
|
|
|
for x in range(0, 10):
|
2022-11-03 21:23:09 -05:00
|
|
|
events[str(x)] = mp.Event()
|
2020-10-10 06:57:43 -05:00
|
|
|
detection_queue = mp.Queue()
|
2022-11-03 21:23:09 -05:00
|
|
|
edgetpu_process_1 = ObjectDetectProcess(
|
|
|
|
detection_queue, events, DetectorTypeEnum.edgetpu, "usb:0"
|
|
|
|
)
|
|
|
|
edgetpu_process_2 = ObjectDetectProcess(
|
|
|
|
detection_queue, events, DetectorTypeEnum.edgetpu, "usb:1"
|
|
|
|
)
|
2020-03-01 07:16:56 -06:00
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
for x in range(0, 10):
|
2022-11-03 21:23:09 -05:00
|
|
|
camera_process = mp.Process(
|
|
|
|
target=start, args=(x, 300, detection_queue, events[str(x)])
|
|
|
|
)
|
|
|
|
camera_process.daemon = True
|
|
|
|
camera_processes.append(camera_process)
|
2020-03-01 07:16:56 -06:00
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
start_time = datetime.datetime.now().timestamp()
|
2020-03-01 07:16:56 -06:00
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
for p in camera_processes:
|
2022-11-03 21:23:09 -05:00
|
|
|
p.start()
|
2020-09-24 06:58:23 -05:00
|
|
|
|
2020-10-10 06:57:43 -05:00
|
|
|
for p in camera_processes:
|
2022-11-03 21:23:09 -05:00
|
|
|
p.join()
|
2020-09-24 06:58:23 -05:00
|
|
|
|
2022-11-03 21:23:09 -05:00
|
|
|
duration = datetime.datetime.now().timestamp() - start_time
|
|
|
|
print(f"Total - Processed for {duration:.2f} seconds.")
|