hailo async processing, data, hef
- hef files for darias yolov5, yolov5m and yolov5s added to repo - minimal data example with image and daria / coco labels - inference now allows an async call, which keeps the connection to the hailo device open, which allows for a higher fps rate (as shown in the test example)
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
*.log
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								data/DJI_0001_0001.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/DJI_0001_0001.jpg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 139 KiB  | 
							
								
								
									
										93
									
								
								data/coco_names.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								data/coco_names.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,93 @@
 | 
			
		||||
{  
 | 
			
		||||
    "0":"unlabeled",
 | 
			
		||||
    "1":"person",
 | 
			
		||||
    "2":"bicycle",
 | 
			
		||||
    "3":"car",
 | 
			
		||||
    "4":"motorcycle",
 | 
			
		||||
    "5":"airplane",
 | 
			
		||||
    "6":"bus",
 | 
			
		||||
    "7":"train",
 | 
			
		||||
    "8":"truck",
 | 
			
		||||
    "9":"boat",
 | 
			
		||||
    "10":"trafficlight",
 | 
			
		||||
    "11":"firehydrant",
 | 
			
		||||
    "12":"streetsign",
 | 
			
		||||
    "13":"stopsign",
 | 
			
		||||
    "14":"parkingmeter",
 | 
			
		||||
    "15":"bench",
 | 
			
		||||
    "16":"bird",
 | 
			
		||||
    "17":"cat",
 | 
			
		||||
    "18":"dog",
 | 
			
		||||
    "19":"horse",
 | 
			
		||||
    "20":"sheep",
 | 
			
		||||
    "21":"cow",
 | 
			
		||||
    "22":"elephant",
 | 
			
		||||
    "23":"bear",
 | 
			
		||||
    "24":"zebra",
 | 
			
		||||
    "25":"giraffe",
 | 
			
		||||
    "26":"hat",
 | 
			
		||||
    "27":"backpack",
 | 
			
		||||
    "28":"umbrella",
 | 
			
		||||
    "29":"shoe",
 | 
			
		||||
    "30":"eyeglasses",
 | 
			
		||||
    "31":"handbag",
 | 
			
		||||
    "32":"tie",
 | 
			
		||||
    "33":"suitcase",
 | 
			
		||||
    "34":"frisbee",
 | 
			
		||||
    "35":"skis",
 | 
			
		||||
    "36":"snowboard",
 | 
			
		||||
    "37":"sportsball",
 | 
			
		||||
    "38":"kite",
 | 
			
		||||
    "39":"baseballbat",
 | 
			
		||||
    "40":"baseballglove",
 | 
			
		||||
    "41":"skateboard",
 | 
			
		||||
    "42":"surfboard",
 | 
			
		||||
    "43":"tennisracket",
 | 
			
		||||
    "44":"bottle",
 | 
			
		||||
    "45":"plate",
 | 
			
		||||
    "46":"wineglass",
 | 
			
		||||
    "47":"cup",
 | 
			
		||||
    "48":"fork",
 | 
			
		||||
    "49":"knife",
 | 
			
		||||
    "50":"spoon",
 | 
			
		||||
    "51":"bowl",
 | 
			
		||||
    "52":"banana",
 | 
			
		||||
    "53":"apple",
 | 
			
		||||
    "54":"sandwich",
 | 
			
		||||
    "55":"orange",
 | 
			
		||||
    "56":"broccoli",
 | 
			
		||||
    "57":"carrot",
 | 
			
		||||
    "58":"hotdog",
 | 
			
		||||
    "59":"pizza",
 | 
			
		||||
    "60":"donut",
 | 
			
		||||
    "61":"cake",
 | 
			
		||||
    "62":"chair",
 | 
			
		||||
    "63":"couch",
 | 
			
		||||
    "64":"pottedplant",
 | 
			
		||||
    "65":"bed",
 | 
			
		||||
    "66":"mirror",
 | 
			
		||||
    "67":"diningtable",
 | 
			
		||||
    "68":"window",
 | 
			
		||||
    "69":"desk",
 | 
			
		||||
    "70":"toilet",
 | 
			
		||||
    "71":"door",
 | 
			
		||||
    "72":"tv",
 | 
			
		||||
    "73":"laptop",
 | 
			
		||||
    "74":"mouse",
 | 
			
		||||
    "75":"remote",
 | 
			
		||||
    "76":"keyboard",
 | 
			
		||||
    "77":"cellphone",
 | 
			
		||||
    "78":"microwave",
 | 
			
		||||
    "79":"oven",
 | 
			
		||||
    "80":"toaster",
 | 
			
		||||
    "81":"sink",
 | 
			
		||||
    "82":"refrigerator",
 | 
			
		||||
    "83":"blender",
 | 
			
		||||
    "84":"book",
 | 
			
		||||
    "85":"clock",
 | 
			
		||||
    "86":"vase",
 | 
			
		||||
    "87":"scissors",
 | 
			
		||||
    "88":"teddybear",
 | 
			
		||||
    "89":"hairdrier",
 | 
			
		||||
    "90":"toothbrush"
 | 
			
		||||
 }
 | 
			
		||||
							
								
								
									
										5
									
								
								data/daria_labels.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								data/daria_labels.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
{  
 | 
			
		||||
    "0":"Label",
 | 
			
		||||
    "1":"Pallet",
 | 
			
		||||
    "2":"Product"
 | 
			
		||||
 }
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								hef/yolov5m.hef
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								hef/yolov5m.hef
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								hef/yolov5m_daria.hef
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								hef/yolov5m_daria.hef
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								hef/yolov5s.hef
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								hef/yolov5s.hef
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										110
									
								
								inference.py
									
									
									
									
									
								
							
							
						
						
									
										110
									
								
								inference.py
									
									
									
									
									
								
							@@ -1,8 +1,11 @@
 | 
			
		||||
import json
 | 
			
		||||
import os
 | 
			
		||||
import time
 | 
			
		||||
t
 | 
			
		||||
 | 
			
		||||
import ipdb
 | 
			
		||||
 | 
			
		||||
from PIL import Image
 | 
			
		||||
from threading import Thread
 | 
			
		||||
 | 
			
		||||
from detection_tools.utils.visualization_utils import \
 | 
			
		||||
            visualize_boxes_and_labels_on_image_array
 | 
			
		||||
@@ -59,8 +62,8 @@ class DataHandler:
 | 
			
		||||
        return coco_names
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def _get_labels(self, label_name):
 | 
			
		||||
        filename = os.path.join(os.path.dirname(__file__), label_name + '.json')
 | 
			
		||||
    def get_labels(self, path):
 | 
			
		||||
        filename = os.path.join(os.path.dirname(__file__), path)
 | 
			
		||||
        names = json.load(open(filename))
 | 
			
		||||
        names = {int(k): {'id': int(k), 'name': str(v)} for (k, v) in names.items()}
 | 
			
		||||
        return names
 | 
			
		||||
@@ -279,22 +282,79 @@ class HailoHandler:
 | 
			
		||||
        out = [infer_results[i.name] for i in self.output_vstream_infos]
 | 
			
		||||
        return out
 | 
			
		||||
 | 
			
		||||
    def start_hailo_thread(self):
 | 
			
		||||
        self.hailo_async = True
 | 
			
		||||
        self.hailo_block = False
 | 
			
		||||
        self.input_data = None
 | 
			
		||||
        self.hailo_thread = Thread(target=self._hailo_async)
 | 
			
		||||
        self.hailo_thread.start()
 | 
			
		||||
 | 
			
		||||
    def _hailo_async(self):
 | 
			
		||||
        with InferVStreams(self.network_group, self.input_vstreams_params, self.output_vstreams_params)\
 | 
			
		||||
                as infer_pipeline:
 | 
			
		||||
            with self.network_group.activate(self.network_group_params):
 | 
			
		||||
                self._hailo_async_loop(infer_pipeline)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def process_yolo5():
 | 
			
		||||
    def _hailo_async_loop(self, infer_pipeline):
 | 
			
		||||
        while self.hailo_async:
 | 
			
		||||
            if(not self.hailo_block and type(self.input_data) != type(None)):
 | 
			
		||||
                self.infer_results = None
 | 
			
		||||
                self.hailo_block = True
 | 
			
		||||
                infer_results = infer_pipeline.infer(self.input_data)
 | 
			
		||||
                self.infer_results = [infer_results[i.name] for i in self.output_vstream_infos]
 | 
			
		||||
                self.input_data = None
 | 
			
		||||
                self.hailo_block = False
 | 
			
		||||
 | 
			
		||||
    def hailo_input(self, input_data):
 | 
			
		||||
        while self.hailo_block:
 | 
			
		||||
            time.sleep(0.01)
 | 
			
		||||
        self.hailo_block = True
 | 
			
		||||
        self.input_data = input_data
 | 
			
		||||
        self.input_data = {self.input_vstream_info.name: input_data}
 | 
			
		||||
        self.infer_results = None
 | 
			
		||||
        self.hailo_block = False
 | 
			
		||||
 | 
			
		||||
    def hailo_output(self):
 | 
			
		||||
        while self.hailo_block:
 | 
			
		||||
            time.sleep(0.01)
 | 
			
		||||
        return self.infer_results
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def stop_hailo_thread(self):
 | 
			
		||||
        self.hailo_async = False
 | 
			
		||||
        self.hailo_thread.join()
 | 
			
		||||
 | 
			
		||||
def test_async_yolo5():
 | 
			
		||||
    imageMeta = ImageMeta(640, 640, 3)
 | 
			
		||||
    processor = YoloProcessing(imageMeta, classes=3)
 | 
			
		||||
    data = DataHandler('./minimal_data', imageMeta)
 | 
			
		||||
    data = DataHandler('./data', imageMeta)
 | 
			
		||||
    data.load_data(processor.preproc)
 | 
			
		||||
 | 
			
		||||
    hailo = HailoHandler('hef/yolov5m_22_2.hef')
 | 
			
		||||
    out = hailo.run_hailo(data.dataset)
 | 
			
		||||
    hailo = HailoHandler('hef/yolov5m_daria.hef')
 | 
			
		||||
    hailo.start_hailo_thread()
 | 
			
		||||
 | 
			
		||||
    fps = 0
 | 
			
		||||
    now = time.time()
 | 
			
		||||
    for i in range(1000):
 | 
			
		||||
        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)
 | 
			
		||||
            out = hailo.hailo_output()
 | 
			
		||||
 | 
			
		||||
    hailo.stop_hailo_thread()
 | 
			
		||||
 | 
			
		||||
    logits = processor.postprocessing(out)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    labels = data._get_labels("daria_names")
 | 
			
		||||
    labels = data.get_labels("data/daria_labels.json")
 | 
			
		||||
    image = visualize_boxes_and_labels_on_image_array(
 | 
			
		||||
        data.dataset[0],
 | 
			
		||||
        logits['detection_boxes'].numpy()[0],
 | 
			
		||||
@@ -308,6 +368,38 @@ def process_yolo5():
 | 
			
		||||
        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)
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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")
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    process_yolo5()
 | 
			
		||||
    test_async_yolo5()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user