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.summary() | |
| # eager off | |
| model.compile(loss='categorical_crossentropy', | |
| optimizer='sgd', |
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
| # 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) |
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
| #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) |
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
| # 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) |
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
| 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])] |
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
| 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) |
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
| 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) |
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
| [ | |
| { | |
| "id": "b819610d-4da6-4a36-80c7-c55a44866526", | |
| "data": [ | |
| { | |
| "text": "Is", | |
| "meta": "@sys.ignore", | |
| "userDefined": true | |
| }, | |
| { |
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
| { | |
| "id": "1effd397-0282-48b1-8f68-7b68d8068061", | |
| "name": "Arlo Image", | |
| "auto": true, | |
| "contexts": [], | |
| "responses": [ | |
| { | |
| "resetContexts": false, | |
| "action": "image.analysis", | |
| "affectedContexts": [ |
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
| @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. |