Hello,
I built the tflite module on the AI since porting it is maybe out of the question
. So anyway, it is built.
I have access to making python3.9 work w/ the TFLite module on the BBAI. I have come across some issues. I am following along in this udacity classroom to get example source and ideas relating to TFLite.
Here is the class online: Udacity . Anyway, if you are using TFLite on the BBAI and wondering how to offload and work w/ examples, I think this post can help the community at large.
Seth
P.S. Here is the source I am working on right now:
import tensorflow as tf
import pathlib
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input
# Create a simple Keras model.
x = [-1, 0, 1, 2, 3, 4]
y = [-3, -1, 1, 3, 5, 7]
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(units=1, input_shape=[1])
])
model.compile(optimizer='sgd', loss='mean_squared_error')
model.fit(x, y, epochs=200, verbose=1)
export_dir = 'saved_model/1'
tf.saved_model.save(model, export_dir)
# Convert the model.
converter = tf.lite.TFLiteConverter.from_saved_model(export_dir)
tflite_model = converter.convert()
tflite_model_file = pathlib.Path('model.tflite')
tflite_model_file.write_bytes(tflite_model)
# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Test the TensorFlow Lite model on random input data.
input_shape = input_details[0]['shape']
inputs, outputs = [], []
for _ in range(100):
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
tflite_results = interpreter.get_tensor(output_details[0]['index'])
# Test the TensorFlow model on random input data.
tf_results = model(tf.constant(input_data))
output_data = np.array(tf_results)
inputs.append(input_data[0][0])
outputs.append(output_data[0][0])
plt.plot(inputs, outputs, 'r')
plt.show()
try:
from google.colab import files
files.download(tflite_model_file)
except:
pass
Now…from what I understand so far, I think I need to supply a working, say, Debian Distro w/ TensorFlow on it so this software can ultimately make the TensorFlow-Lite module. Does this seem correct? Anyway…if you are into making the BBAI guess with education on what may take place w/ tensors, please reply. I am sure we can work on this together or w/ another portion of the community.