<jupyter_start><jupyter_text>CNC vs VMC> This notebook creates image classifier to distinguish between CNC lathes which are called CNCs and Vertical Machining centers which are called VMCs- toc: false- branch: master- badges: true- comments: true- categories: [fastai,CNC, lathe, VMC, colab, image classifier]- author: <NAME>- image: images/some_folder/your_image.png- hide: false- search_exclude: true- metadata_key1: metadata_value1- metadata_key2: metadata_value2 This notebook is based on lessons 1 and parts of lesson 2 of fast.ai MOOC by <NAME>. We will do the following in this notebook :1.   Scrap images from internet to create database.2.   Build image classifier using fast.ai library.1.  We will be using icrawler to build this database. It can build large databases with minimal code. I was able to develop 600 images of one type and 700 images of other type.<jupyter_code>!pip install icrawler
from icrawler.builtin import (BingImageCrawler, GoogleImageCrawler)
import logging
keyword = 'Vertical maching center'
!mkdir VMCvsCNC

VMCvsCNC ='./content/VMC'
search_filters_google = dict()

google_crawler = GoogleImageCrawler(downloader_threads=4,storage={'root_dir': VMCvsCNC},log_level=logging.INFO)
google_crawler.crawl(keyword=keyword, filters=search_filters_google, max_num=1000)

keyword = 'CNC lathe'
!mkdir CNC
VMCvsCNC ='./content/CNC'
search_filters_google = dict()

google_crawler = GoogleImageCrawler(downloader_threads=4,storage={'root_dir': VMCvsCNC},log_level=logging.INFO)
google_crawler.crawl(keyword=keyword, filters=search_filters_google, max_num=1000)<jupyter_output>2019-09-30 03:11:14,003 - INFO - icrawler.crawler - start crawling...
2019-09-30 03:11:14,004 - INFO - icrawler.crawler - starting 1 feeder threads...
2019-09-30 03:11:14,006 - INFO - icrawler.crawler - starting 1 parser threads...
2019-09-30 03:11:14,015 - INFO - icrawler.crawler - starting 4 downloader threads...
2019-09-30 03:11:14,549 - INFO - parser - parsing result page https://www.google.com/search?q=CNC+lathe&ijn=0&start=0&tbs=&tbm=isch
2019-09-30 03:11:14,777 - INFO - downloader - image #1	https://www.normanmachinetool.com/wp-content/uploads/2018/08/7966-CLAUSING-COLCHESTER-CNC200-STORM-2-AXIS-CNC-LATHE-1.jpg
2019-09-30 03:11:14,959 - INFO - downloader - image #2	https://34h49vqklr1l2ajs1xqmjgzq-wpengine.netdna-ssl.com/wp-content/uploads/2018/07/1440-cnc-lathe-600x527.png
2019-09-30 03:11:14,975 - INFO - downloader - image #3	https://image.made-in-china.com/2f0j00DjMavLPtsBgR/Precision-China-CNC-Lathe-Machine-Price-CK6152E-.jpg
2019-09-30 03:11:15,075 - INFO - downloader - ima[...]<jupyter_text>2. Now we will build the model to classify our images. We can train them on the basis of wither accuracy or error rate. I am using accuracy to train the model.<jupyter_code>!curl -s https://course.fast.ai/setup/colab | bash
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from fastai.vision import *
from fastai.metrics import error_rate, accuracy
!pwd
path = "/content/content"
tfms = get_transforms(do_flip=False)
data = (ImageList.from_folder(path)
        .split_by_rand_pct()
        .label_from_folder()
        .transform(tfms, size=224)
        .databunch()
        .normalize(imagenet_stats))<jupyter_output><empty_output><jupyter_text>We take a peak into our image collection.<jupyter_code>data.show_batch(rows=3, figsize=(10,8))
print(data.classes)
len(data.classes), data.c
learn = cnn_learner(data, models.resnet34, metrics=accuracy)
learn.fit_one_cycle(5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11290780141843972, 'fraction_numerical': 0.06921985815602837, 'mean_word_length': 5.110918544194107, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '16402', 'license': 'Apache-2.0', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1231, 'n_words': 304, 'path': '_notebooks/2020-04-03-CNC vs VMC.ipynb', 'repo_name': 'sharan19/Sharan-s-Blog', 'size': '3538'}