This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "github.com/nbortolotti/tflitego" | |
| ) | |
| // topSpecie provide the name of the specia infered by the model |
This file contains hidden or 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
| import os | |
| import argparse | |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' | |
| def fun(x): | |
| return x + 1 |
This file contains hidden or 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
| import numpy as np | |
| import tflite_runtime.interpreter as tflite | |
| interpreter = tflite.Interpreter(model_path="converted_model.tflite") # change the tflite model | |
| interpreter.allocate_tensors() | |
| input_details = interpreter.get_input_details() | |
| output_details = interpreter.get_output_details() |
This file contains hidden or 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
| #converting to tflite from keras | |
| converter = tf.lite.TFLiteConverter.from_keras_model(model) | |
| tflite_model = converter.convert() | |
| open ("iris_lite.tflite" , "wb") .write(tflite_model) |
This file contains hidden or 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
| import pandas as pd | |
| import numpy as np | |
| import tensorflow as tf | |
| train_ds_url = "http://download.tensorflow.org/data/iris_training.csv" | |
| test_ds_url = "http://download.tensorflow.org/data/iris_test.csv" | |
| ds_columns = ['SepalLength', 'SepalWidth','PetalLength', 'PetalWidth', 'Plants'] | |
| species = np.array(['Setosa', 'Versicolor', 'Virginica'], dtype=np.object) |
This file contains hidden or 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
| model = tf.keras.Sequential([ | |
| tf.keras.layers.Dense(16, input_dim=4), | |
| tf.keras.layers.Dense(3, activation=tf.nn.softmax), | |
| ]) | |
| model.compile(loss='categorical_crossentropy', | |
| optimizer='sgd', | |
| metrics=['accuracy']) |
This file contains hidden or 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
| #tensorflow and tensorflow_probability imports | |
| import tensorflow as tf | |
| import tensorflow_probability as tfp | |
| #matplotlib import for visualizations | |
| import matplotlib.pyplot as plt; | |
| # numpy to support transformation and visualiation | |
| import numpy as np; |
This file contains hidden or 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
| new_specie = np.array([7.9,3.8,6.4,2.0]) | |
| predition = np.around(model.predict(np.expand_dims(new_specie, axis=0))).astype(np.int)[0] | |
| print("This species should be %s" % species[predition.astype(np.bool)][0]) |
This file contains hidden or 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
| loss, accuracy = model.evaluate(dataset_test, steps=32) | |
| print("loss:%f"% (loss)) | |
| print("accuracy: %f"% (accuracy)) |
This file contains hidden or 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
| model.fit(dataset, steps_per_epoch=32, epochs=100, verbose=0) |
NewerOlder