-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code updated to better explain github issue: tensorflow/tflite-micro#…
- Loading branch information
1 parent
021500c
commit f5d2c46
Showing
10 changed files
with
12,571 additions
and
12,514 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(esp-yolov8n-test) | ||
project(esp-mbnetv2-test) |
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
#pragma once | ||
|
||
extern const unsigned char esp_yolo_model[]; | ||
extern const unsigned int esp_yolo_model_len; | ||
extern const unsigned char esp_mobile_net_model[]; | ||
extern const unsigned int esp_mobile_net_model_len; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
from tensorflow.keras.utils import load_img, img_to_array | ||
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input, decode_predictions | ||
|
||
interpreter = tf.lite.Interpreter(model_path="mobilenet_v2_35_quantized.tflite", experimental_preserve_all_tensors=True) | ||
interpreter.allocate_tensors() | ||
|
||
input_details = interpreter.get_input_details()[0] | ||
output_details = interpreter.get_output_details()[0] | ||
|
||
input_scale, input_zero = input_details["quantization"] | ||
output_scale, output_zero = output_details["quantization"] | ||
|
||
img = img_to_array(load_img("bus.jpg", target_size=(224, 224))) | ||
# img.astype(np.uint8).tofile("bus.raw") | ||
|
||
img = np.expand_dims(img, axis=0) | ||
img = preprocess_input(img) | ||
img = (img / input_scale) + input_zero | ||
img = img.astype(np.int8) | ||
|
||
print(img.flatten()[:100]) | ||
interpreter.set_tensor(input_details['index'], img) | ||
interpreter.invoke() | ||
|
||
output = interpreter.get_tensor(output_details['index']).astype(np.float32) | ||
output = (output - output_zero) * output_scale | ||
predictions = decode_predictions(output, top=5) | ||
print(predictions) | ||
|
||
tensor_details = interpreter.get_tensor_details() | ||
tensor = None | ||
for t in tensor_details: | ||
if t['name'] == 'mobilenetv2_0.35_224_1/global_average_pooling2d_1/Mean': | ||
tensor = t | ||
|
||
print("\n\n") | ||
print(interpreter.get_tensor(tensor['index']).flatten()[:100]) |