Skip to content

Instantly share code, notes, and snippets.

@tkeyo
Last active June 26, 2021 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkeyo/fbfe5d63c5b71b1faaa6fa5621b0b451 to your computer and use it in GitHub Desktop.
Save tkeyo/fbfe5d63c5b71b1faaa6fa5621b0b451 to your computer and use it in GitHub Desktop.
inference_list = []
DEBOUNCE_THRESHOLD = 9
TIME_DIFF = 450 #ms
for st in inference_step: # looping through the whole length of the dataset
inference = model.score(data)
if inference in [1,2,3]:
inference_list.append((time, inference))
# if there are more or equal than 9 predictions in a list
# AND
# the difference between the first and last predictions is > 450 ms
if len(inference_list) >= DEBOUNCE_THRESHOLD and (inference_list[-1][0] - inference_list[0][0]) >= TIME_DIFF:
inferences = [x[1] for x in inferences_list[:DEBOUNCE_THRESHOLD]] # gets the first 8 predictions
inference_final = max(set(inferences), key=inferences.count) # gets the most frequent value
inference_list = [] # cleans up the list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment