I am writing a code using the Google AIY vision kit and its APIs. I have a loop which calls the face_detection model continuously every 30 secs. The loop works perfectly fine for the first 2 iterations but when it reaches to the 3rd iteration my display monitor switches off and shows me that no HDMI is detected even though the program is still running in the background. Along with the display monitor, I have connected my laptop to my raspberry pi using a VNC viewer. So, when the display monitor goes off the VNC viewer keeps operating and the command line keeps displaying the output. How can I fix this issue and keep the monitor open for all the period of running the code?

This is the main function:

def main():
  with PiCamera(sensor_mode=4, resolution=(1640, 1232), framerate=30) as camera:
     while durationOver():
if __name__ == '__main__':

This the face_detection_inference function:

def face_detection_inference(camera,args):

 """Face detection camera inference example.""" 

# Annotator renders in software so use a smaller size and scale results
# for increased performance.
annotator = Annotator(camera, dimensions=(320, 240))
scale_x = 320 / 1640
scale_y = 240 / 1232

# Incoming boxes are of the form (x, y, width, height). Scale and
# transform to the form (x1, y1, x2, y2).
def transform(bounding_box):
    x, y, width, height = bounding_box
    return (scale_x * x, scale_y * y, scale_x * (x + width), scale_y * (y + height))
    with CameraInference(face_detection.model()) as inference:
        cam_tick = time.time()
        for result in inference.run(args.num_frames):
            time_passed = time.time() - cam_tick
            if time_passed>5:
            faces = face_detection.get_faces(result)
            for face in faces:
                annotator.bounding_box(transform(face.bounding_box), fill=0)
            print('#%05d (%5.2f fps): num_faces=%d' %(inference.count, inference.rate, len(faces)))
  • 1
    you described your observation ... now, please ask a question
    – jsotola
    Commented Nov 2, 2020 at 16:57

1 Answer 1


Updates: I have figured out the cause of this issue, it seems like when the annotator is called several times in the loop it allocates several resources and doesn't release them between loops. The issue was fixed by avoiding to use Annotator and remove it from inside the loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.