diff --git a/notebooks/Classify Data Example-kNN.ipynb b/notebooks/Classify Data Example-kNN.ipynb index b1486b4..bd4fe98 100644 --- a/notebooks/Classify Data Example-kNN.ipynb +++ b/notebooks/Classify Data Example-kNN.ipynb @@ -20,7 +20,9 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import turicreate as turi" @@ -185,7 +187,9 @@ { "cell_type": "code", "execution_count": 5, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "userinput = turi.SFrame({\n", diff --git a/notebooks/Classify Image Example-ResNet50.ipynb b/notebooks/Classify Image Example-ResNet50.ipynb index 429b44c..1f87a3b 100644 --- a/notebooks/Classify Image Example-ResNet50.ipynb +++ b/notebooks/Classify Image Example-ResNet50.ipynb @@ -38,7 +38,9 @@ { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "url = \"data/food_images\"" @@ -130,8 +132,8 @@ ], "source": [ "data = turi.image_analysis.load_images(url)\n", - "data['foodType'] = data['path'].apply(lambda path: 'Eggs' if 'eggs' in path else 'Soup')\n", - "data.save('egg_or_soup.sframe')\n", + "data[\"foodType\"] = data[\"path\"].apply(lambda path: \"Eggs\" if \"eggs\" in path else \"Soup\")\n", + "data.save(\"egg_or_soup.sframe\")\n", "data.explore()" ] }, diff --git a/raw_python/classify_data_knn.py b/raw_python/classify_data_knn.py new file mode 100644 index 0000000..bf4e1fc --- /dev/null +++ b/raw_python/classify_data_knn.py @@ -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 diff --git a/raw_python/classify_image_resnet.py b/raw_python/classify_image_resnet.py new file mode 100644 index 0000000..5647378 --- /dev/null +++ b/raw_python/classify_image_resnet.py @@ -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") diff --git a/raw_python/create_data.py b/raw_python/create_data.py new file mode 100644 index 0000000..54a8eaa --- /dev/null +++ b/raw_python/create_data.py @@ -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 ] + }) diff --git a/raw_python/sample_CSV_reading.py b/raw_python/sample_CSV_reading.py new file mode 100644 index 0000000..bf2bc55 --- /dev/null +++ b/raw_python/sample_CSV_reading.py @@ -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 diff --git a/raw_python/sample_reading.py b/raw_python/sample_reading.py deleted file mode 100644 index 079e3c6..0000000 --- a/raw_python/sample_reading.py +++ /dev/null @@ -1,6 +0,0 @@ -# Import Turi Create package -import turicreate as turi -# Reads the data file, in this case we will read data from a CSV file -dataBuffer = turi.SFrame.read_csv('/Users/ahmedbekhit/Documents/Data/Development/TuriCreate/SampleCSVFile_119kb.csv', header=False) -dataBuffer.head(5) -print dataBuffer