-
-
Save Amplify4177/082d457b7a7e5abe8b0958ccd434ecd6 to your computer and use it in GitHub Desktop.
ESP32 ML - C Optimization for Input Normalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STATIC mp_obj_t norm_input(mp_obj_t input, mp_obj_t multiplier, mp_obj_t adder) { | |
// Check if input is a list | |
if (mp_obj_is_type(input, &mp_type_list)) { | |
// Create a new list to hold normalized values | |
mp_obj_t outputs = mp_obj_new_list(0, NULL); | |
// Convert input list to pointer and get length | |
mp_obj_list_t *input_c = MP_OBJ_TO_PTR(input); | |
unsigned int list_len = input_c->len; | |
for (int i = 0; i < list_len; i++) { | |
// relu each item in input list | |
mp_obj_t normalized = norm_input(input_c->items[i], multiplier, adder); | |
// append to new list | |
mp_obj_list_append(outputs, normalized); | |
} | |
return outputs; | |
} else { | |
// relu the scalar input | |
float input_f = mp_obj_get_float(input); | |
float multiplier_f = mp_obj_get_float(multiplier); | |
float adder_f = mp_obj_get_float(adder); | |
return mp_obj_new_float((input_f+adder_f)*multiplier_f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment