diff --git a/scripts/examples/25-Machine-Learning/nn_cifar10.py b/scripts/examples/25-Machine-Learning/nn_cifar10.py index 5ca404af2..24e401f2b 100644 --- a/scripts/examples/25-Machine-Learning/nn_cifar10.py +++ b/scripts/examples/25-Machine-Learning/nn_cifar10.py @@ -22,7 +22,7 @@ while(True): img = sensor.snapshot() # Take a picture and return the image. out = net.forward(img) max_idx = out.index(max(out)) - score = int(((out[max_idx]+128)/255)*100) + score = int(out[max_idx]*100) if (score < 70): score_str = "??:??%" else: diff --git a/scripts/examples/25-Machine-Learning/nn_haar_smile_detection.py b/scripts/examples/25-Machine-Learning/nn_haar_smile_detection.py index cc4e7f397..86d60c333 100644 --- a/scripts/examples/25-Machine-Learning/nn_haar_smile_detection.py +++ b/scripts/examples/25-Machine-Learning/nn_haar_smile_detection.py @@ -32,6 +32,6 @@ while (True): r = [r[0], r[1]+10, int(r[2]*1.1), int(r[2]*1.1)] img.draw_rectangle(r) out = net.forward(img, roi=r, softmax=True) - img.draw_string(r[0], r[1], ':)' if (out[0]/127 > 0.8) else ':(', color=(255), scale=2) + img.draw_string(r[0], r[1], ':)' if (out[0] > 0.8) else ':(', color=(255), scale=2) print(clock.fps()) diff --git a/scripts/examples/25-Machine-Learning/nn_lenet.py b/scripts/examples/25-Machine-Learning/nn_lenet.py index 4dc0063e8..4d1927e48 100644 --- a/scripts/examples/25-Machine-Learning/nn_lenet.py +++ b/scripts/examples/25-Machine-Learning/nn_lenet.py @@ -20,7 +20,7 @@ while(True): img = sensor.snapshot() # Take a picture and return the image. out = net.forward(img.copy().binary([(150, 255)], invert=True)) max_idx = out.index(max(out)) - score = int(((out[max_idx]+128)/255)*100) + score = int(out[max_idx]*100) if (score < 70): score_str = "??:??%" else: diff --git a/src/omv/py/py_nn.c b/src/omv/py/py_nn.c index d08c2dd68..88982a992 100644 --- a/src/omv/py/py_nn.c +++ b/src/omv/py/py_nn.c @@ -50,7 +50,7 @@ STATIC mp_obj_t py_net_forward(uint n_args, const mp_obj_t *args, mp_map_t *kw_a } for (int i=0; ioutput_size; i++) { - mp_obj_list_append(output_list, mp_obj_new_int(net->output_data[i])); + mp_obj_list_append(output_list, mp_obj_new_float(((float) (net->output_data[i] + 128)) / 255)); } fb_alloc_free_till_mark();