-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Import Turi Create package | ||
import turicreate as turi | ||
|
||
# Create an SFrame object. | ||
''' | ||
Each column in the `SFrame` is an `SArray` object. | ||
In the following `SFrame` object, we have created a data buffer (dataset) that specifies the size of each pet's eyes, nose, and head. | ||
Each number in the dataset is a ratio from 15cm. | ||
Note:- The ratios in the dataset are NOT accurate or related to reality. Those are random ratios used for demonstration purposes. | ||
''' | ||
dataBuffer = turi.SFrame({ | ||
"pet_types": ["cat", "dog", "wolf", "cat", "wolf", "dog"], | ||
"eyes": [0.23, 0.64, 0.89, 0.26, 0.93, 0.66 ], | ||
"nose": [0.11, 0.68, 0.78, 0.08, 0.74, 0.57 ], | ||
"head": [0.34, 0.47, 0.66, 0.37, 0.68, 0.45 ] | ||
}) | ||
|
||
# Create a nearest neighbor classifier using the SFrame object above. | ||
classifier = turi.nearest_neighbor_classifier.create(dataBuffer, target="pet_types") | ||
|
||
# Edit the input below. Make sure the numbers are between 0 and 1. | ||
userinput = turi.SFrame({ | ||
"eyes": [0.32], | ||
"nose": [0.20], | ||
"head": [0.42] | ||
}) | ||
|
||
# Predict the input using the nearest neighbor classifier. | ||
result = classifier.predict(userinput, max_neighbors=2) | ||
print result |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Import Turi Create package | ||
import turicreate as turi | ||
|
||
# Refrence the dataset path | ||
url = "/Users/ahmedbekhit/Documents/Data/Development/TuriCreate/repo/turicreate-notebook/notebooks/data/food_images" | ||
|
||
# Label the dataset | ||
## Load the dataset folder image content using the image_analysis property | ||
data = turi.image_analysis.load_images(url) | ||
## Create a "foodType" key for each image in the dataset to specify whether it's an Egg or Soup, based on which folder it's located in. | ||
data["foodType"] = data["path"].apply(lambda path: "Eggs" if "eggs" in path else "Soup") | ||
## Export the labeled images as an SFrame object in order to use it while creating our image classifier. | ||
data.save("egg_or_soup.sframe") | ||
## Visualize the new labeled images list. | ||
data.explore() | ||
|
||
# Load the SFrame object that contains the labeled images. | ||
dataBuffer = turi.SFrame("egg_or_soup.sframe") | ||
|
||
# Randmly split the SFrame object | ||
''' | ||
90% of the data from the original SFrame object will be used to train the image classifier. | ||
10% of the data from the original SFrame object will be used to test the image classifier. | ||
''' | ||
trainingBuffers, testingBuffers = dataBuffer.random_split(0.9) | ||
|
||
# Train the image classifier using the Residual Network architecture and pre-trained model. | ||
model = turi.image_classifier.create(trainingBuffers, target="foodType", model="resnet-50") | ||
|
||
# Evaluate the test data to determine the model accuracy | ||
evaluations = model.evaluate(testingBuffers) | ||
|
||
# Save the Turi Create model to retrieve it later | ||
model.save("egg_or_soup.model") | ||
|
||
# Export our new trained image classification model for Core ML. | ||
model.export_coreml("FoodClassifier.mlmodel") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Import Turi Create package | ||
import turicreate as turi | ||
|
||
# Create an SFrame object. | ||
''' | ||
Each column in the `SFrame` is an `SArray` object. | ||
In the following `SFrame` object, we have created a data buffer (dataset) that specifies the size of each pet's eyes, nose, and head. | ||
Each number in the dataset is a ratio from 15cm. | ||
Note:- The ratios in the dataset are NOT accurate or related to reality. Those are random ratios used for demonstration purposes. | ||
''' | ||
dataBuffer = turi.SFrame({ | ||
"pet_types": ["cat", "dog", "wolf", "cat", "wolf", "dog"], | ||
"eyes": [0.23, 0.64, 0.89, 0.26, 0.93, 0.66 ], | ||
"nose": [0.11, 0.68, 0.78, 0.08, 0.74, 0.57 ], | ||
"head": [0.34, 0.47, 0.66, 0.37, 0.68, 0.45 ] | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Import Turi Create package | ||
import turicreate as turi | ||
# Reads the data file, in this case we will read data from a CSV file | ||
''' | ||
Each column in the `SFrame` is an `SArray` object. | ||
In the following line of code, the parameter `header` is set to `False` because the **CSV** data file we're using doesn't have a header. | ||
Note:- The `header` parameter is `True` by default and if we didn't set it to `False` it would show us the first **n+1** rows since it counts the first as a header automatically. | ||
''' | ||
dataBuffer = turi.SFrame.read_csv('/Users/ahmedbekhit/Documents/Data/Development/TuriCreate/SampleCSVFile_119kb.csv', header=False) | ||
|
||
# Load the first 5 rows. | ||
dataBuffer.head(5) | ||
|
||
print dataBuffer |
This file was deleted.
Oops, something went wrong.