2020-03-01 14:16:56 +01:00
|
|
|
import os
|
|
|
|
from statistics import mean
|
|
|
|
import multiprocessing as mp
|
2019-06-05 04:38:41 +02:00
|
|
|
import numpy as np
|
2020-03-01 14:16:56 +01:00
|
|
|
import datetime
|
2020-08-22 14:05:20 +02:00
|
|
|
from frigate.edgetpu import LocalObjectDetector, EdgeTPUProcess, RemoteObjectDetector, load_labels
|
2019-06-05 04:38:41 +02:00
|
|
|
|
2020-03-01 14:16:56 +01:00
|
|
|
my_frame = np.expand_dims(np.full((300,300,3), 1, np.uint8), axis=0)
|
|
|
|
labels = load_labels('/labelmap.txt')
|
2019-06-05 04:38:41 +02:00
|
|
|
|
2020-03-01 14:16:56 +01:00
|
|
|
######
|
|
|
|
# Minimal same process runner
|
|
|
|
######
|
2020-09-24 13:58:23 +02:00
|
|
|
# object_detector = LocalObjectDetector()
|
2020-03-01 14:16:56 +01:00
|
|
|
# tensor_input = np.expand_dims(np.full((300,300,3), 0, np.uint8), axis=0)
|
2019-06-05 04:38:41 +02:00
|
|
|
|
2020-03-01 14:16:56 +01:00
|
|
|
# start = datetime.datetime.now().timestamp()
|
2019-06-05 04:38:41 +02:00
|
|
|
|
2020-03-01 14:16:56 +01:00
|
|
|
# frame_times = []
|
|
|
|
# for x in range(0, 1000):
|
|
|
|
# start_frame = datetime.datetime.now().timestamp()
|
2019-06-05 04:38:41 +02:00
|
|
|
|
2020-03-01 14:16:56 +01: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")
|
|
|
|
|
|
|
|
######
|
|
|
|
# Separate process runner
|
|
|
|
######
|
2020-09-24 13:58:23 +02:00
|
|
|
def start(id, num_detections, detection_queue, event):
|
|
|
|
object_detector = RemoteObjectDetector(str(id), '/labelmap.txt', detection_queue, event)
|
2020-03-01 14:16:56 +01:00
|
|
|
start = datetime.datetime.now().timestamp()
|
|
|
|
|
|
|
|
frame_times = []
|
|
|
|
for x in range(0, num_detections):
|
|
|
|
start_frame = datetime.datetime.now().timestamp()
|
|
|
|
detections = object_detector.detect(my_frame)
|
|
|
|
frame_times.append(datetime.datetime.now().timestamp()-start_frame)
|
|
|
|
|
|
|
|
duration = datetime.datetime.now().timestamp()-start
|
|
|
|
print(f"{id} - Processed for {duration:.2f} seconds.")
|
|
|
|
print(f"{id} - Average frame processing time: {mean(frame_times)*1000:.2f}ms")
|
|
|
|
|
2020-09-24 13:58:23 +02:00
|
|
|
event = mp.Event()
|
|
|
|
edgetpu_process = EdgeTPUProcess({'1': event})
|
2020-03-01 14:16:56 +01:00
|
|
|
|
2020-09-24 13:58:23 +02: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 14:16:56 +01:00
|
|
|
|
|
|
|
####
|
|
|
|
# Multiple camera processes
|
|
|
|
####
|
2020-09-24 13:58:23 +02:00
|
|
|
# camera_processes = []
|
2020-03-01 14:16:56 +01:00
|
|
|
|
2020-09-24 13:58:23 +02:00
|
|
|
# pipes = {}
|
|
|
|
# for x in range(0, 10):
|
|
|
|
# pipes[x] = mp.Pipe(duplex=False)
|
2020-03-01 14:16:56 +01:00
|
|
|
|
2020-09-24 13:58:23 +02:00
|
|
|
# edgetpu_process = EdgeTPUProcess({str(key): value[1] for (key, value) in pipes.items()})
|
2020-03-01 14:16:56 +01:00
|
|
|
|
2020-09-24 13:58:23 +02:00
|
|
|
# for x in range(0, 10):
|
|
|
|
# camera_process = mp.Process(target=start, args=(x, 100, edgetpu_process.detection_queue, pipes[x][0]))
|
|
|
|
# camera_process.daemon = True
|
|
|
|
# camera_processes.append(camera_process)
|
2020-03-01 14:16:56 +01:00
|
|
|
|
2020-09-24 13:58:23 +02:00
|
|
|
# start = datetime.datetime.now().timestamp()
|
|
|
|
|
|
|
|
# for p in camera_processes:
|
|
|
|
# p.start()
|
|
|
|
|
|
|
|
# for p in camera_processes:
|
|
|
|
# p.join()
|
|
|
|
|
|
|
|
# duration = datetime.datetime.now().timestamp()-start
|
|
|
|
# print(f"Total - Processed for {duration:.2f} seconds.")
|