Skip to content

Instantly share code, notes, and snippets.

View nbortolotti's full-sized avatar
🏠
Working from home

Nicolas Bortolotti nbortolotti

🏠
Working from home
View GitHub Profile
@nbortolotti
nbortolotti / iris_tflitego.go
Last active January 22, 2021 16:01
Iris inference using tfliego. more information about example: https://github.com/nbortolotti/tflitego_examples/ & and about the library: https://github.com/nbortolotti/tflitego
package main
import (
"fmt"
"log"
"github.com/nbortolotti/tflitego"
)
// topSpecie provide the name of the specia infered by the model
import os
import argparse
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
def fun(x):
return x + 1
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()
#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)
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)
@nbortolotti
nbortolotti / keras_example_irismodelbuild.py
Created January 7, 2019 12:53
Keras Model definition
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'])
@nbortolotti
nbortolotti / tf_probability_hospital_example.py
Last active November 28, 2018 12:59
Tensorflow Probability, what is the probability that of 6 randomly selected patients, 4 will recover? article support
#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;
@nbortolotti
nbortolotti / use_model.py
Created August 15, 2018 13:31
[use model]Experience with iris dataset using tf.keras & tensorflow
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])
@nbortolotti
nbortolotti / model_evaluation.py
Last active August 15, 2018 13:30
[model evaluation]Experience with iris dataset using tf.keras & tensorflow
loss, accuracy = model.evaluate(dataset_test, steps=32)
print("loss:%f"% (loss))
print("accuracy: %f"% (accuracy))
@nbortolotti
nbortolotti / train_model.py
Created August 15, 2018 13:26
[train model]Experience with iris dataset using tf.keras & tensorflow
model.fit(dataset, steps_per_epoch=32, epochs=100, verbose=0)