def process_frame(data_url): global _last_activity_time start_time = time.time() _last_activity_time = start_time # process image img = data_url_to_pil(data_url) input_dict = model.preprocess(img) inference_start = time.time() output_dict = model.run(input_dict) inference_end = time.time() payload = model.postprocess(img, output_dict) # build payload end_time = time.time() _last_activity_time = end_time print("[INFO] {} processing time: {:.6f} seconds" .format(model.name, end_time - start_time)) if envars.INCLUDE_TOTAL_TIME(): payload['time'] = end_time - start_time inference_total = inference_end - inference_start if envars.INCLUDE_INFERENCE_TIME() and inference_total > 0.01: payload['inference_time'] = inference_total sio.emit('frame_complete', payload) # request a new frame if envars.AUTO_RUN(): sio.emit('frame_request')
def process_frame(data_url): global _last_activity_time global _counter start_time = time.time() _last_activity_time = start_time # build annotation payload = { 'name': _model_name, 'annotations': [{ 'kind': 'box', 'x': _counter, 'y': 0, 'width': 50, 'height': 50, 'label': 'box_test', 'confidence': 1 }] } end_time = time.time() _last_activity_time = end_time print("[INFO] {} processing time: {:.6f} seconds".format( _model_name, end_time - start_time)) sio.emit('frame_complete', payload) _counter = (_counter + 10) % 400 # request a new frame if envars.AUTO_RUN(): sio.emit('frame_request')
def poll_timer(): global _last_activity_time while True: time.sleep(envars.POLL_TIME()) elapsed_time = time.time() - _last_activity_time if envars.AUTO_RUN() and elapsed_time > envars.INACTIVITY_THRESHOLD(): print('No activity. Querying controller again') sio.emit('frame_request')
def process_frame(data_url): global _last_activity_time start_time = time.time() _last_activity_time = start_time img = _decode_img(data_url) # convert back to webp out_url = _encode_img(img) # build payload end_time = time.time() _last_activity_time = end_time print("[INFO] {} processing time: {:.6f} seconds".format( _model_name, end_time - start_time)) payload = { 'name': _model_name, 'annotations': [{ 'kind': 'image', 'data': out_url }], 'clock_time': end_time - start_time } sio.emit('frame_complete', payload) # request a new frame if envars.AUTO_RUN(): sio.emit('frame_request')