Hello Mates. I manage to get the Hailo’s Object Detection Example code to work for my models.
The issue is, I have 2 models:
1st model: gets a video as input, detects and Crop boxes for each frame, and saves it as .jpg file;
2nd model: receives the .jpg file and does OCR on it.
with the example code i can just use 1 model, or i get the “OUT_OF_PHYSICAL_DEVICE” error.
I tried to modify the “utils.py” file on the example code to add the model switch function, here’s what i did:
self.switch_state: int = 1
self.crop_hef = "yolov8s.hef"
self.ocr_hef = "yolov8n.hef"
self.hef = None
#self.hef = self.get_model()
self.set_model()
self.target = VDevice(self.params)
self.infer_model = self.target.create_infer_model(self.get_infer_model())
self.infer_model.set_batch_size(batch_size)
if input_type is not None:
self._set_input_type(input_type)
if output_type is not None:
self._set_output_type(output_type)
self.output_type = output_type
self.send_original_frame = send_original_frame
def get_infer_model(self):
if self.switch_state == 0:
return self.crop_hef
else:
return self.ocr_hef
def release_vdevice(self):
#VDevice.release(self)
print("release method")
self.params = None
self.target.release()
#self.target.release
def set_vdevice(self):
self.release_vdevice()
self.params = VDevice.create_params()
self.params.scheduling_algorithm = HailoSchedulingAlgorithm.ROUND_ROBIN
self.target = VDevice(self.params)
def set_infer_model(self):
self.infer_model = self.target.create_infer_model(self.get_infer_model())
def set_model(self) -> None:
print("Set Model Called!!!")
if self.switch_state == 0:
self.switch_state = 1
self.hef = HEF(self.ocr_hef)
else:
self.switch_state = 0
self.hef = HEF(self.crop_hef)
this is what i have on the “utils.py” script, i call the functions in the following order:
release_vdevice(); #Clears VDevice
set_vdevice(); #Sets it up
set_model(); #Sets new model
set_infer_model() #Creates infer model from the new set model
There is a While loop inside the “ObjecDetection.py” file, in the postprocessing method, this method calls “extract_detections” and “draw_detections”, in my case, it does it for each frame of the video for the 1st model, in draw_detections, i save the new bbox cropped image with cv2.imwrite, and then i call the above functions, in order to stop the current model, switch to another model, and start inference.
When i start the main script “ObjectDetection.py” it runs the first model normally, but when the condition to switch model comes up and the script starts calling the above functions, it gives me this error:
[HailoRT] [error] CHECK_SUCCESS failed with status=HAILO_NOT_FOUND(61)
If i dont call the release_vdevice() function, it just gives the me “OUT OF PHYSICAL DEVICE” error.
In conclusion, i need help implementing a model switcher algorithm into this Hailo’s code example, ideally in the “utils.py” file.
By the way im reading the Hailo Documentation on " Python Inference Tutorial - Multi Process Service and Model Scheduler", i started a few minutes ago, and its bit unfriendly, maybe its because i’ve using the Hailo code example for a longer, i feel more comfortable with it, but any help regarding that, will be appreciated as well.
Heres the link for the hailo code example im refereing, im using the python version object detection: