{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "melanoma_classification.ipynb", "version": "0.3.2", "views": {}, "default_view": {}, "provenance": [ { "file_id": "1WB_KFS_v-cUGcQlLCui1zY2yi9_53FRO", "timestamp": 1521599432486 }, { "file_id": "1gxbV3jGpAScBlpDwmunpw9v-KkdDW-Mm", "timestamp": 1519788607959 } ], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "accelerator": "GPU" }, "cells": [ { "metadata": { "id": "Weolwx_o-XW0", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Installing TuriCreate. This is our main package. TuriCreate is open sourced. \n", "# You can get more info about TuriCreate at https://github.com/apple/turicreate\n", "\n", "!pip install turicreate" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "xZ0sRri2FBZD", "colab_type": "text" }, "cell_type": "markdown", "source": [ "" ] }, { "metadata": { "id": "p6r25vQo_1-8", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 1 } ], "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "cc000212-b4f1-4cf3-ccb9-1204d20654b1", "executionInfo": { "status": "ok", "timestamp": 1521599523242, "user_tz": 300, "elapsed": 515, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# Finding the directory we are in\n", "!ls" ], "execution_count": 2, "outputs": [ { "output_type": "stream", "text": [ "datalab\r\n" ], "name": "stdout" } ] }, { "metadata": { "id": "mDm-xDqJKXTL", "colab_type": "text" }, "cell_type": "markdown", "source": [ "Next code block will mount your google drive. This will help you to access files stored in your google drive. \n", "Druing installation you see a prompt with a link -Please, open the following URL in a web browser: https://accounts.google.com/o ....\n", "Click the link. Copy and paste the code from the link in the form field and press enter. \n", "Sometime You may have to run this code block twice. I think this is a bug in colab. " ] }, { "metadata": { "id": "RK-IDnlMKWy7", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "MW6q3iD0E_zK", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "!apt-get install -y -qq software-properties-common python-software-properties module-init-tools\n", "!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null\n", "!apt-get update -qq 2>&1 > /dev/null\n", "!apt-get -y install -qq google-drive-ocamlfuse fuse\n", "from google.colab import auth\n", "auth.authenticate_user()\n", "from oauth2client.client import GoogleCredentials\n", "creds = GoogleCredentials.get_application_default()\n", "import getpass\n", "!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL\n", "vcode = getpass.getpass()\n", "!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "QoafsczbH8Wt", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Mount your google drive to access files from it \n", "!mkdir -p drive\n", "!google-drive-ocamlfuse drive" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "TETZgUL1H8F4", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# The image folder that I am using for this tutorial is located in my google drive under 'app' folder\n", "# So we need to change directory to the 'app' folder\n", "\n", "import os\n", "os.chdir(\"drive/app\")" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "bKGEoRTkH7y6", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 1 } ], "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "9694539a-152c-4317-bbcc-5e4af41edb6c", "executionInfo": { "status": "ok", "timestamp": 1521599653818, "user_tz": 300, "elapsed": 696, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# make sure that we are in the right folder \n", "!ls" ], "execution_count": 7, "outputs": [ { "output_type": "stream", "text": [ "cats-dogs.sframe ImageFolder MelanomaImages wisconsin_breast_cancer.csv\r\n" ], "name": "stdout" } ] }, { "metadata": { "id": "WRB_f_VqIyjh", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# importing turicreate as tc\n", "\n", "import turicreate as tc" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "wgIccMR5Fzzd", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Loading the images from MelanomaImages in my google drive. This 'MelanomaImages' has 2 folders\n", "# 'melanoma' and 'benign'\n", "\n", "\n", "data = tc.image_analysis.load_images('MelanomaImages', with_path=True)" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "0YNnUEwgGnDk", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Labelling each images in the SFrame using the folder name\n", "\n", "data['label'] = data['path'].apply(lambda path: 'melanoma' if '/melanoma' in path else 'benign')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "ZuEWrVXfGrfv", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 1 } ], "base_uri": "https://localhost:8080/", "height": 421 }, "outputId": "e0df3b46-8a90-488c-b3ef-a393ee6b72f9", "executionInfo": { "status": "ok", "timestamp": 1521600470404, "user_tz": 300, "elapsed": 645, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "#Displaying the first 5 rows in data to make sure that we got everything right \n", "\n", "data.tail()" ], "execution_count": 12, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pathimagelabel
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4439 Width: 6708melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4441 Width: 6661melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4401 Width: 6681melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4459 Width: 6627melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4439 Width: 6668melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4419 Width: 6648melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4422 Width: 6661melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4420 Width: 6641melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4441 Width: 6640melanoma
/content/drive/app/Melano
maImages/melanoma/ISI ...
Height: 4459 Width: 6708melanoma
\n", "[10 rows x 3 columns]
\n", "
" ], "text/plain": [ "Columns:\n", "\tpath\tstr\n", "\timage\tImage\n", "\tlabel\tstr\n", "\n", "Rows: 10\n", "\n", "Data:\n", "+-------------------------------+--------------------------+----------+\n", "| path | image | label |\n", "+-------------------------------+--------------------------+----------+\n", "| /content/drive/app/Melanom... | Height: 4439 Width: 6708 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4441 Width: 6661 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4401 Width: 6681 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4459 Width: 6627 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4439 Width: 6668 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4419 Width: 6648 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4422 Width: 6661 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4420 Width: 6641 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4441 Width: 6640 | melanoma |\n", "| /content/drive/app/Melanom... | Height: 4459 Width: 6708 | melanoma |\n", "+-------------------------------+--------------------------+----------+\n", "[10 rows x 3 columns]" ] }, "metadata": { "tags": [] }, "execution_count": 12 } ] }, { "metadata": { "id": "1x6lnbn_GuJK", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Saving the data frame to our google drive \n", "data.save('melanoma.sframe')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "ub9_7HX6G5SP", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Splitting the image data set into training (80%) and testing (20%) data\n", "train_data, test_data = data.random_split(0.8)" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "TImA_m7xOLHJ", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Switching to the root directory in our google virtual machine\n", "os.chdir(\"/usr\")" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "DDDdAW_5OdTQ", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# installing other packahes to use GPU\n", "!apt install libnvrtc8.0" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "sMMijcQ8OdF5", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 2 } ], "base_uri": "https://localhost:8080/", "height": 51 }, "outputId": "5e15f0a3-27c5-4a85-8f8c-c356ec713de2", "executionInfo": { "status": "ok", "timestamp": 1521600642163, "user_tz": 300, "elapsed": 2006, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# uninstalling previous versions of mxnet\n", "!pip uninstall -y mxnet" ], "execution_count": 17, "outputs": [ { "output_type": "stream", "text": [ "Uninstalling mxnet-0.12.1:\n", " Successfully uninstalled mxnet-0.12.1\n" ], "name": "stdout" } ] }, { "metadata": { "id": "kIePe_6JPRH4", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 19 } ], "base_uri": "https://localhost:8080/", "height": 381 }, "outputId": "ece90dee-fac2-4be6-ce4a-a884d0deeb00", "executionInfo": { "status": "ok", "timestamp": 1521600658918, "user_tz": 300, "elapsed": 12824, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# Installing the latest version of mxnet to work with turi create\n", "!pip install mxnet==1.1.0" ], "execution_count": 18, "outputs": [ { "output_type": "stream", "text": [ "Collecting mxnet==1.1.0\n", " Downloading mxnet-1.1.0-py2.py3-none-manylinux1_x86_64.whl (23.7MB)\n", "\u001b[K 100% |################################| 23.8MB 60kB/s \n", "\u001b[?25hRequirement already satisfied: requests==2.18.4 in ./local/lib/python3.6/dist-packages (from mxnet==1.1.0)\n", "Collecting graphviz==0.8.1 (from mxnet==1.1.0)\n", " Downloading graphviz-0.8.1-py2.py3-none-any.whl\n", "Collecting numpy<=1.13.3 (from mxnet==1.1.0)\n", " Downloading numpy-1.13.3-cp36-cp36m-manylinux1_x86_64.whl (17.0MB)\n", "\u001b[K 100% |################################| 17.0MB 84kB/s \n", "\u001b[?25hRequirement already satisfied: certifi>=2017.4.17 in ./local/lib/python3.6/dist-packages (from requests==2.18.4->mxnet==1.1.0)\n", "Requirement already satisfied: urllib3<1.23,>=1.21.1 in ./local/lib/python3.6/dist-packages (from requests==2.18.4->mxnet==1.1.0)\n", "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./local/lib/python3.6/dist-packages (from requests==2.18.4->mxnet==1.1.0)\n", "Requirement already satisfied: idna<2.7,>=2.5 in ./local/lib/python3.6/dist-packages (from requests==2.18.4->mxnet==1.1.0)\n", "Installing collected packages: graphviz, numpy, mxnet\n", " Found existing installation: graphviz 0.8.2\n", " Uninstalling graphviz-0.8.2:\n", " Successfully uninstalled graphviz-0.8.2\n", " Found existing installation: numpy 1.14.2\n", " Uninstalling numpy-1.14.2:\n", " Successfully uninstalled numpy-1.14.2\n", "Successfully installed graphviz-0.8.1 mxnet-1.1.0 numpy-1.13.3\n" ], "name": "stdout" } ] }, { "metadata": { "id": "ZNLCKas7OUs5", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# making sure that mxnet is working\n", "# If you get an error here, you need to fix it before going forward\n", "import mxnet as m2" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "alAuHnRvG6Vr", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 7 }, { "item_id": 8 }, { "item_id": 9 }, { "item_id": 10 }, { "item_id": 11 }, { "item_id": 12 }, { "item_id": 13 }, { "item_id": 14 }, { "item_id": 15 }, { "item_id": 16 }, { "item_id": 17 }, { "item_id": 18 }, { "item_id": 19 }, { "item_id": 20 }, { "item_id": 21 }, { "item_id": 22 }, { "item_id": 23 }, { "item_id": 24 }, { "item_id": 25 }, { "item_id": 26 }, { "item_id": 27 }, { "item_id": 28 }, { "item_id": 29 }, { "item_id": 30 }, { "item_id": 31 } ], "base_uri": "https://localhost:8080/", "height": 661 }, "outputId": "ad3f744a-1401-4d33-c882-70409463ca05", "executionInfo": { "status": "ok", "timestamp": 1521601052455, "user_tz": 300, "elapsed": 380430, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# Automatically pick the right model based on your data.\n", "# Note: Because the dataset is large, model creation may take hours.\n", "\n", "model = tc.image_classifier.create(train_data, target='label')" ], "execution_count": 20, "outputs": [ { "output_type": "stream", "text": [ "Downloading https://docs-assets.developer.apple.com/turicreate/models/resnet-50-symbol.json\n", "Download completed: /var/tmp/model_cache/resnet-50-symbol.json\n", "Downloading https://docs-assets.developer.apple.com/turicreate/models/resnet-50-0000.params\n", "Download completed: /var/tmp/model_cache/resnet-50-0000.params\n", "Resizing images...\n", "Performing feature extraction on resized images...\n", "Completed 512/734\n", "Completed 734/734\n", "PROGRESS: Creating a validation set from 5 percent of training data. This may take a while.\n", " You can set ``validation_set=None`` to disable validation tracking.\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "data": { "text/html": [ "
WARNING: The number of feature dimensions in this problem is very large in comparison with the number of examples. Unless an appropriate regularization value is set, this model may not provide accurate predictions for a validation/test set.
" ], "text/plain": [ "WARNING: The number of feature dimensions in this problem is very large in comparison with the number of examples. Unless an appropriate regularization value is set, this model may not provide accurate predictions for a validation/test set." ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
WARNING: Detected extremely low variance for feature(s) '__image_features__' because all entries are nearly the same.\n",
              "Proceeding with model training using all features. If the model does not provide results of adequate quality, exclude the above mentioned feature(s) from the input dataset.
" ], "text/plain": [ "WARNING: Detected extremely low variance for feature(s) '__image_features__' because all entries are nearly the same.\n", "Proceeding with model training using all features. If the model does not provide results of adequate quality, exclude the above mentioned feature(s) from the input dataset." ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Logistic regression:
" ], "text/plain": [ "Logistic regression:" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
--------------------------------------------------------
" ], "text/plain": [ "--------------------------------------------------------" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Number of examples          : 699
" ], "text/plain": [ "Number of examples : 699" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Number of classes           : 2
" ], "text/plain": [ "Number of classes : 2" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Number of feature columns   : 1
" ], "text/plain": [ "Number of feature columns : 1" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Number of unpacked features : 2048
" ], "text/plain": [ "Number of unpacked features : 2048" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Number of coefficients      : 2049
" ], "text/plain": [ "Number of coefficients : 2049" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
Starting L-BFGS
" ], "text/plain": [ "Starting L-BFGS" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
--------------------------------------------------------
" ], "text/plain": [ "--------------------------------------------------------" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
+-----------+----------+-----------+--------------+-------------------+---------------------+
" ], "text/plain": [ "+-----------+----------+-----------+--------------+-------------------+---------------------+" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| Iteration | Passes   | Step size | Elapsed Time | Training-accuracy | Validation-accuracy |
" ], "text/plain": [ "| Iteration | Passes | Step size | Elapsed Time | Training-accuracy | Validation-accuracy |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
+-----------+----------+-----------+--------------+-------------------+---------------------+
" ], "text/plain": [ "+-----------+----------+-----------+--------------+-------------------+---------------------+" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 1         | 7        | 0.000009  | 1.407496     | 0.589413          | 0.657143            |
" ], "text/plain": [ "| 1 | 7 | 0.000009 | 1.407496 | 0.589413 | 0.657143 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 2         | 10       | 5.000000  | 1.614489     | 0.728183          | 0.771429            |
" ], "text/plain": [ "| 2 | 10 | 5.000000 | 1.614489 | 0.728183 | 0.771429 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 3         | 11       | 5.000000  | 1.714628     | 0.765379          | 0.714286            |
" ], "text/plain": [ "| 3 | 11 | 5.000000 | 1.714628 | 0.765379 | 0.714286 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 4         | 12       | 5.000000  | 1.810076     | 0.589413          | 0.657143            |
" ], "text/plain": [ "| 4 | 12 | 5.000000 | 1.810076 | 0.589413 | 0.657143 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 5         | 14       | 1.000000  | 1.960559     | 0.789700          | 0.771429            |
" ], "text/plain": [ "| 5 | 14 | 1.000000 | 1.960559 | 0.789700 | 0.771429 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 6         | 15       | 1.000000  | 2.066136     | 0.723891          | 0.685714            |
" ], "text/plain": [ "| 6 | 15 | 1.000000 | 2.066136 | 0.723891 | 0.685714 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
| 10        | 20       | 1.000000  | 2.569017     | 0.831187          | 0.828571            |
" ], "text/plain": [ "| 10 | 20 | 1.000000 | 2.569017 | 0.831187 | 0.828571 |" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
+-----------+----------+-----------+--------------+-------------------+---------------------+
" ], "text/plain": [ "+-----------+----------+-----------+--------------+-------------------+---------------------+" ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
TERMINATED: Iteration limit reached.
" ], "text/plain": [ "TERMINATED: Iteration limit reached." ] }, "metadata": { "tags": [] } }, { "output_type": "display_data", "data": { "text/html": [ "
This model may not be optimal. To improve it, consider increasing `max_iterations`.
" ], "text/plain": [ "This model may not be optimal. To improve it, consider increasing `max_iterations`." ] }, "metadata": { "tags": [] } } ] }, { "metadata": { "id": "GjhQrTTzRxjN", "colab_type": "text" }, "cell_type": "markdown", "source": [ "Took only about 7 minutes to do this with GPU!" ] }, { "metadata": { "id": "VzziTY2aG-A5", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# storing the prediction \n", "\n", "predictions = model.predict(test_data)" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "clbk_WE7R-q2", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 3 } ], "base_uri": "https://localhost:8080/", "height": 86 }, "outputId": "49fda9a0-359f-428a-d374-3d66a1561e70", "executionInfo": { "status": "ok", "timestamp": 1521601353680, "user_tz": 300, "elapsed": 97321, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# Evaluating the model \n", "\n", "metrics = model.evaluate(test_data)\n", "print(metrics['accuracy'])" ], "execution_count": 23, "outputs": [ { "output_type": "stream", "text": [ "Resizing images...\n", "Performing feature extraction on resized images...\n", "Completed 183/183\n", "0.825136612021858\n" ], "name": "stdout" } ] }, { "metadata": { "id": "38gNPKZRSrhL", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 1 } ], "base_uri": "https://localhost:8080/", "height": 207 }, "outputId": "1ba507c4-7500-419e-d7cb-ce1a77d52835", "executionInfo": { "status": "ok", "timestamp": 1521601378853, "user_tz": 300, "elapsed": 317, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "# Printing confusion matrix\n", "\n", "print (\"Confusion Matrix : \\n%s\" % metrics['confusion_matrix'])" ], "execution_count": 24, "outputs": [ { "output_type": "stream", "text": [ "Confusion Matrix : \n", "+--------------+-----------------+-------+\n", "| target_label | predicted_label | count |\n", "+--------------+-----------------+-------+\n", "| benign | benign | 102 |\n", "| benign | melanoma | 7 |\n", "| melanoma | melanoma | 49 |\n", "| melanoma | benign | 25 |\n", "+--------------+-----------------+-------+\n", "[4 rows x 3 columns]\n", "\n" ], "name": "stdout" } ] }, { "metadata": { "id": "FXJqEP6ci6gM", "colab_type": "text" }, "cell_type": "markdown", "source": [ "\n", "```\n", "\n", "> Statistic Value Confidence interval \n", "\n", "\n", "> Sensitivity 66.22%\t 54.28% to 76.81%\n", "\n", "\n", "\n", "> Specificity 93.58 %\t 87.22% to 97.38%\n", "\n", "\n", "> PPV 87.50% \t 77.05% to 93.59%\n", "\n", "\n", "> NPV 80.31 % 74.71% to 84.93%\n", "\n", "\n", "> Accuracy 82.51% \t 76.22% to 87.72%\n", "\n", "\n", "```" ] }, { "metadata": { "id": "Q4GoAum5TP4v", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Save the model for later use in Turi Create\n", "model.save('melanoma.model')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "XPdqOGADURz2", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Export for use in Core ML\n", "model.export_coreml('MyMelanomaClassifier.mlmodel')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "6X51lMk0U04m", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "output_extras": [ { "item_id": 1 } ], "base_uri": "https://localhost:8080/", "height": 51 }, "outputId": "823d3e54-432f-4e26-b0c1-547cade1ceb8", "executionInfo": { "status": "ok", "timestamp": 1521601450071, "user_tz": 300, "elapsed": 643, "user": { "displayName": "Endocrine Doctor", "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128", "userId": "106981773189993416592" } } }, "cell_type": "code", "source": [ "!ls" ], "execution_count": 27, "outputs": [ { "output_type": "stream", "text": [ "MyMelanomaClassifier.mlmodel games lib\t local\t sbin src\r\n", "bin\t\t\t include lib64-nvidia melanoma.model share\r\n" ], "name": "stdout" } ] }, { "metadata": { "id": "O6PUln9hWcBQ", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "# Downloading the model for use in Xcode\n", "\n", "from google.colab import files\n", "\n", "files.download('MyMelanomaClassifier.mlmodel')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "lKbWi2xqc1J3", "colab_type": "code", "colab": { "autoexec": { "startup": false, "wait_interval": 0 } } }, "cell_type": "code", "source": [ "" ], "execution_count": 0, "outputs": [] } ] }