From 429c1862546a2cbda044f459865e6cee7d9aa314 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sun, 24 May 2020 18:57:49 +0530 Subject: Publish deploy 2020-05-24 18:57 --- .../index.html | 62 +++++++--------------- 1 file changed, 19 insertions(+), 43 deletions(-) (limited to 'posts/2020-01-16-Image-Classifier-Using-Turicreate/index.html') diff --git a/posts/2020-01-16-Image-Classifier-Using-Turicreate/index.html b/posts/2020-01-16-Image-Classifier-Using-Turicreate/index.html index 187a8d2..f21e657 100644 --- a/posts/2020-01-16-Image-Classifier-Using-Turicreate/index.html +++ b/posts/2020-01-16-Image-Classifier-Using-Turicreate/index.html @@ -1,20 +1,12 @@ Creating a Custom Image Classifier using Turicreate to detect Smoke and Fire | Navan Chauhan
6 minute readCreated on January 16, 2020Last modified on January 19, 2020

Creating a Custom Image Classifier using Turicreate to detect Smoke and Fire

For setting up Kaggle with Google Colab, please refer to my previous post

Dataset

Mounting Google Drive

import os from google.colab import drive drive.mount('/content/drive') -
- -

Downloading Dataset from Kaggle

os.environ['KAGGLE_CONFIG_DIR'] = "/content/drive/My Drive/" +

Downloading Dataset from Kaggle

os.environ['KAGGLE_CONFIG_DIR'] = "/content/drive/My Drive/" !kaggle datasets download ashutosh69/fire-and-smoke-dataset !unzip "fire-and-smoke-dataset.zip" -
- -

Pre-Processing

!mkdir default smoke fire -
- -


!ls data/data/img_data/train/default/*.jpg -
- -


img_1002.jpg img_20.jpg img_519.jpg img_604.jpg img_80.jpg +

Pre-Processing

!mkdir default smoke fire +


!ls data/data/img_data/train/default/*.jpg +


img_1002.jpg img_20.jpg img_519.jpg img_604.jpg img_80.jpg img_1003.jpg img_21.jpg img_51.jpg img_60.jpg img_8.jpg img_1007.jpg img_22.jpg img_520.jpg img_61.jpg img_900.jpg img_100.jpg img_23.jpg img_521.jpg 'img_62 (2).jpg' img_920.jpg @@ -47,49 +39,39 @@ img_204.jpg img_501.jpg img_601.jpg img_78.jpg img_205.jpg img_502.jpg img_602.jpg img_79.jpg img_206.jpg img_50.jpg img_603.jpg img_7.jpg -
- -

The image files are not actually JPEG, thus we first need to save them in the correct format for Turicreate

from PIL import Image +

The image files are not actually JPEG, thus we first need to save them in the correct format for Turicreate

from PIL import Image import glob folders = ["default","smoke","fire"] for folder in folders: n = 1 - for file in glob.glob("./data/data/img_data/train/" + folder + "/*.jpg"): - im = Image.open(file) + for file in glob.glob("./data/data/img_data/train/" + folder + "/*.jpg"): + im = Image.open(file) rgb_im = im.convert('RGB') rgb_im.save((folder + "/" + str(n) + ".jpg"), quality=100) n +=1 - for file in glob.glob("./data/data/img_data/train/" + folder + "/*.jpg"): - im = Image.open(file) + for file in glob.glob("./data/data/img_data/train/" + folder + "/*.jpg"): + im = Image.open(file) rgb_im = im.convert('RGB') rgb_im.save((folder + "/" + str(n) + ".jpg"), quality=100) n +=1 -
- -


!mkdir train +


!mkdir train !mv default ./train !mv smoke ./train !mv fire ./train -
- -

Making the Image Classifier

Making an SFrame

!pip install turicreate -
- -


import turicreate as tc +

Making the Image Classifier

Making an SFrame

!pip install turicreate +


import turicreate as tc import os -data = tc.image_analysis.load_images("./train", with_path=True) +data = tc.image_analysis.load_images("./train", with_path=True) data["label"] = data["path"].apply(lambda path: os.path.basename(os.path.dirname(path))) -print(data) +print(data) data.save('fire-smoke.sframe') -
- -


+-------------------------+------------------------+ +


+-------------------------+------------------------+ | path | image | +-------------------------+------------------------+ | ./train/default/1.jpg | Height: 224 Width: 224 | @@ -123,9 +105,7 @@ [2028 rows x 3 columns] Note: Only the head of the SFrame is printed. You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns. -
- -

Making the Model

import turicreate as tc +

Making the Model

import turicreate as tc # Load the data data = tc.SFrame('fire-smoke.sframe') @@ -141,16 +121,14 @@ # Evaluate the model and print the results metrics = model.evaluate(test_data) -print(metrics['accuracy']) +print(metrics['accuracy']) # Save the model for later use in Turi Create model.save('fire-smoke.model') # Export for use in Core ML model.export_coreml('fire-smoke.mlmodel') -
- -


Performing feature extraction on resized images... +


Performing feature extraction on resized images... Completed 64/1633 Completed 128/1633 Completed 192/1633 @@ -208,6 +186,4 @@ Completed 384/395 Completed 395/395 0.9316455696202531 -
- -

We just got an accuracy of 94% on Training Data and 97% on Validation Data!

Tagged with:
\ No newline at end of file +

We just got an accuracy of 94% on Training Data and 97% on Validation Data!

Tagged with:
\ No newline at end of file -- cgit v1.2.3