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 / build_model.py
Created August 15, 2018 13:15
[build model]Experience with iris dataset using tf.keras & tensorflow
model = tf.keras.Sequential([
tf.keras.layers.Dense(16, input_dim=4),
tf.keras.layers.Dense(3, activation=tf.nn.softmax),
])
model.summary()
# eager off
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
@nbortolotti
nbortolotti / build_dataset.py
Created August 15, 2018 13:09
[build dataset]Experience with iris dataset using tf.keras & tensorflow
# Build the dataset
# train
dataset = tf.data.Dataset.from_tensor_slices((train_plantfeatures, y_categorical))
dataset = dataset.batch(32)
dataset = dataset.shuffle(1000)
dataset = dataset.repeat()
#test
dataset_test = tf.data.Dataset.from_tensor_slices((test_plantfeatures, y_categorical_test))
dataset_test = dataset_test.batch(32)
@nbortolotti
nbortolotti / downloading.py
Last active August 15, 2018 13:05
[Downloading]Experience with iris dataset using tf.keras & tensorflow.py
#Data download and dataset creation witout tf.data
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)
#Load data
categories='Plants'
train_path = tf.keras.utils.get_file(train_ds_url.split('/')[-1], train_ds_url)
test_path = tf.keras.utils.get_file(test_ds_url.split('/')[-1], test_ds_url)
# imports
import tensorflow as tf
import pandas as pd
import numpy as np
# Data download and dataset creation witout tf.data
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)
def dominant_color(np_object):
pixs = np_object.reshape((-1, 3))
n_colors = 5
flags = cv2.KMEANS_RANDOM_CENTERS
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
_, labels, centroids = cv2.kmeans(np.float32(pixs), n_colors, None, criteria, 10, flags)
palette = np.uint8(centroids)
dominant_object_color = palette[np.argmax(itemfreq(labels)[:, -1])]
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
for image_path in TEST_IMAGE_PATHS:
image = Image.open(image_path)
image_np = load_image_into_numpy_array(image)
def slice_box_objects(n_image, img_with, img_height, cla, b, sco, category="tie", confident=0.7):
objects = []
for i, box in enumerate(np.squeeze(b)):
if category_index[np.squeeze(cla)[i]]['name'] == category:
if np.squeeze(sco)[i] > confident:
crop = n_image[int(box[0] * img_height):int(box[2] * img_height),
int(box[1] * img_with):int(box[3] * img_with)]
plt.imshow(crop)
plt.show()
objects.append(crop)
[
{
"id": "b819610d-4da6-4a36-80c7-c55a44866526",
"data": [
{
"text": "Is",
"meta": "@sys.ignore",
"userDefined": true
},
{
@nbortolotti
nbortolotti / Arlo Imagen.json
Created January 26, 2018 21:36
intent part of the dialogflow agent
{
"id": "1effd397-0282-48b1-8f68-7b68d8068061",
"name": "Arlo Image",
"auto": true,
"contexts": [],
"responses": [
{
"resetContexts": false,
"action": "image.analysis",
"affectedContexts": [
@nbortolotti
nbortolotti / method_arlo_service_assistant
Created January 26, 2018 18:36
method to take an snapshot using arlo system as a service [Flask and PyArlo]
@app.route('/arlo', methods=['POST'])
def tensor_photo():
try:
# connect to Arlo using PyArlo library.
arlo = PyArlo('user', read_file("pass.txt"))
req = request.get_json(silent=True, force=True)
action = req.get('result').get('action')
# detect action from DialogFlow agent description.