From d75527f7eecc4e2fcdd18ab157412506717c8adb Mon Sep 17 00:00:00 2001 From: navanchauhan Date: Mon, 7 Nov 2022 23:36:11 -0700 Subject: add blog post --- ...20-01-16-Image-Classifier-Using-Turicreate.html | 72 ++++++++++++++-------- 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'docs/posts/2020-01-16-Image-Classifier-Using-Turicreate.html') diff --git a/docs/posts/2020-01-16-Image-Classifier-Using-Turicreate.html b/docs/posts/2020-01-16-Image-Classifier-Using-Turicreate.html index 4235b29..5056a82 100644 --- a/docs/posts/2020-01-16-Image-Classifier-Using-Turicreate.html +++ b/docs/posts/2020-01-16-Image-Classifier-Using-Turicreate.html @@ -49,31 +49,40 @@

Mounting Google Drive

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

Downloading Dataset from Kaggle

-
os.environ['KAGGLE_CONFIG_DIR'] = "/content/drive/My Drive/"
+
+
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
-
+
+
!mkdir default smoke fire
+
+

\

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

\

-
img_1002.jpg   img_20.jpg     img_519.jpg     img_604.jpg       img_80.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
@@ -106,11 +115,13 @@
 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
+
+
from PIL import Image
 import glob
 
 
@@ -127,26 +138,32 @@
     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
-
+
+
!pip install turicreate
+
+

\

-
import turicreate as tc
+
+
import turicreate as tc
 import os
 
 data = tc.image_analysis.load_images("./train", with_path=True)
@@ -156,11 +173,13 @@
 print(data)
 
 data.save('fire-smoke.sframe')
-
+
+

\

-
+-------------------------+------------------------+
+
+
+-------------------------+------------------------+
 |           path          |         image          |
 +-------------------------+------------------------+
 |  ./train/default/1.jpg  | Height: 224 Width: 224 |
@@ -194,11 +213,13 @@
 [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
+
+
import turicreate as tc
 
 # Load the data
 data =  tc.SFrame('fire-smoke.sframe')
@@ -221,11 +242,13 @@
 
 # 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
@@ -283,7 +306,8 @@
 Completed 384/395
 Completed 395/395
 0.9316455696202531
-
+
+

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

-- cgit v1.2.3