adds image visualization
This commit is contained in:
71
inference.py
71
inference.py
@ -175,7 +175,30 @@ class YoloProcessing:
|
||||
return box_centers, box_scales, objness, class_pred
|
||||
|
||||
|
||||
def postprocessing(self, endnodes):
|
||||
def process_to_picture(self, endnodes, data):
|
||||
logits = self.postprocessing(endnodes)
|
||||
self.visualize_image(logits, data)
|
||||
|
||||
|
||||
def visualize_image(self, logits, data):
|
||||
labels = data.get_labels("data/daria_labels.json")
|
||||
image = visualize_boxes_and_labels_on_image_array(
|
||||
data.dataset[0],
|
||||
logits['detection_boxes'].numpy()[0],
|
||||
logits['detection_classes'][0],
|
||||
logits['detection_scores'].numpy()[0],
|
||||
labels,
|
||||
use_normalized_coordinates=True,
|
||||
max_boxes_to_draw=100,
|
||||
min_score_thresh=.5,
|
||||
agnostic_mode=False,
|
||||
line_thickness=4)
|
||||
|
||||
Image.fromarray(np.uint8(image)).save('/home/maintenance/test.png')
|
||||
print("Successfully saved image")
|
||||
|
||||
|
||||
def postprocessing(self, endnodes, count):
|
||||
"""
|
||||
endnodes is a list of 3 output tensors:
|
||||
endnodes[0] - stride 32 of input
|
||||
@ -235,6 +258,7 @@ class YoloProcessing:
|
||||
max_total_size=100)
|
||||
|
||||
|
||||
|
||||
# adding offset to the class prediction and cast to integer
|
||||
def translate_coco_2017_to_2014(nmsed_classes):
|
||||
return np.vectorize(COCO_17_14.get)(nmsed_classes).astype(np.int32)
|
||||
@ -242,6 +266,8 @@ class YoloProcessing:
|
||||
nmsed_classes = tf.cast(tf.add(nmsed_classes, labels_offset), tf.int16)
|
||||
nmsed_classes = translate_coco_2017_to_2014(nmsed_classes)
|
||||
|
||||
print(count)
|
||||
|
||||
return {'detection_boxes': nmsed_boxes,
|
||||
'detection_scores': nmsed_scores,
|
||||
'detection_classes': nmsed_classes,
|
||||
@ -336,53 +362,43 @@ def test_async_yolo5():
|
||||
|
||||
fps = 0
|
||||
now = time.time()
|
||||
for i in range(1000):
|
||||
for i in range(100):
|
||||
fps += 1
|
||||
if now + 1 < time.time():
|
||||
print(fps)
|
||||
fps = 0
|
||||
now = time.time()
|
||||
|
||||
hailo.hailo_input(data.dataset)
|
||||
out = None
|
||||
while(out == None):
|
||||
time.sleep(0.01)
|
||||
time.sleep(0.0001)
|
||||
out = hailo.hailo_output()
|
||||
|
||||
Thread(target=processor.postprocessing, args=[out, i]).start()
|
||||
|
||||
hailo.stop_hailo_thread()
|
||||
|
||||
logits = processor.postprocessing(out)
|
||||
|
||||
|
||||
labels = data.get_labels("data/daria_labels.json")
|
||||
image = visualize_boxes_and_labels_on_image_array(
|
||||
data.dataset[0],
|
||||
logits['detection_boxes'].numpy()[0],
|
||||
logits['detection_classes'][0],
|
||||
logits['detection_scores'].numpy()[0],
|
||||
labels,
|
||||
use_normalized_coordinates=True,
|
||||
max_boxes_to_draw=100,
|
||||
min_score_thresh=.5,
|
||||
agnostic_mode=False,
|
||||
line_thickness=4)
|
||||
|
||||
Image.fromarray(np.uint8(image)).save('/home/maintenance/test.png')
|
||||
print("Successfully saved image")
|
||||
|
||||
|
||||
|
||||
def test_process_yolo5():
|
||||
|
||||
imageMeta = ImageMeta(640, 640, 3)
|
||||
processor = YoloProcessing(imageMeta, classes=3)
|
||||
processor = YoloProcessing(imageMeta, classes=4)
|
||||
data = DataHandler('./data', imageMeta)
|
||||
data.load_data(processor.preproc)
|
||||
|
||||
hailo = HailoHandler('hef/yolov5m_daria.hef')
|
||||
out = hailo.run_hailo(data.dataset)
|
||||
|
||||
logits = processor.postprocessing(out)
|
||||
now = time.time()
|
||||
fps = 0
|
||||
for i in range(100):
|
||||
fps += 1
|
||||
if now + 1 < time.time():
|
||||
print(fps)
|
||||
fps = 0
|
||||
now = time.time()
|
||||
|
||||
out = hailo.run_hailo(data.dataset)
|
||||
logits = processor.postprocessing(out)
|
||||
|
||||
|
||||
labels = data.get_labels("data/daria_labels.json")
|
||||
@ -398,7 +414,6 @@ def test_process_yolo5():
|
||||
agnostic_mode=False,
|
||||
line_thickness=4)
|
||||
|
||||
Image.fromarray(np.uint8(image)).save('/home/maintenance/test.png')
|
||||
print("Successfully saved image")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user