Reader small image

You're reading from  Mobile Artificial Intelligence Projects

Product typeBook
Published inMar 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789344073
Edition1st Edition
Languages
Right arrow
Authors (3):
Karthikeyan NG
Karthikeyan NG
author image
Karthikeyan NG

Karthikeyan NG is the Head of Engineering and Technology at the Indian lifestyle and fashion retail brand. He served as a software engineer at Symantec Corporation and has worked with 2 US-based startups as an early employee and has built various products. He has 9+ years of experience in various scalable products using Web, Mobile, ML, AR, and VR technologies. He is an aspiring entrepreneur and technology evangelist. His interests lie in exploring new technologies and innovative ideas to resolve a problem. He has also bagged prizes from more than 15 hackathons, is a TEDx speaker and a speaker at technology conferences and meetups as well as guest lecturer at a Bengaluru University. When not at work, he is found trekking.
Read more about Karthikeyan NG

Arun Padmanabhan
Arun Padmanabhan
author image
Arun Padmanabhan

Arun Padmanabhan is a Machine Learning consultant with over 8 years of experience building end-to-end machine learning solutions and applications. Currently working with a couple of start-ups in the Financial and Insurance industries, he specializes in automating manual workflows using AI and creating Machine Vision and NLP applications. In past, he has led the data science team of a Singapore based product startup in the restaurant domain. He also has built stand-alone and integrated Machine Learning solutions in the Manufacturing, Shipping and e-commerce domains over the years. His interests are in research, development and applications of Artificial Intelligence and Deep Architectures.
Read more about Arun Padmanabhan

Matt Cole
Matt Cole
author image
Matt Cole

Matt R. Cole is a developer and author with 30 years' experience. Matt is the owner of Evolved AI Solutions, a provider of advanced Machine Learning/Bio-AI, Microservice and Swarm technologies. Matt is recognized as a leader in Microservice and Artificial Intelligence development and design. As an early pioneer of VOIP, Matt developed the VOIP system for NASA for the International Space Station and Space Shuttle. Matt also developed the first Bio Artificial Intelligence framework which completely integrates mirror and canonical neurons. In his spare time Matt authors books, and continues his education taking every available course in advanced mathematics, AI/ML/DL, Quantum Mechanics/Physics, String Theory and Computational Neuroscience.
Read more about Matt Cole

View More author details
Right arrow

Building an ML Model to Predict Car Damage Using TensorFlow

In this chapter, we will build a system that detects the level of damage that's been done to a vehicle by analyzing photographs using transfer learning. A solution like this will be helpful in reducing the cost of insurance claims, as well as making the process simpler for vehicle owners. If the system is implemented properly, in an ideal scenario, the user will upload a bunch of photographs of the damaged vehicle, the photos will go through damage assessment, and the insurance claim will be processed automatically.

There are a lot of risks and challenges involved in implementing a perfect solution for this use case. To start with, there are multiple unknown conditions that could have caused damage to the car. We are not aware of the outdoor environment, surrounding objects, light in the area, and the quality of...

Transfer learning basics

To implement the car damage prediction system, we are going to build our own TensorFlow-based machine learning (ML) model for the vehicle datasets. Millions of parameters are needed with modern recognition models. We need a lot of time and data to train a new model from scratch, as well as hundreds of Graphical Processing Units (GPUs) or Tensor Processing Units (TPUs) that run for hours.

Transfer learning makes this task easier by taking an existing model that is already trained and reusing it on a new model. In our example, we will use the feature extraction capabilities from the MobileNet model and train our own classifiers on top of it. Even if we don't get 100% accuracy, this works best in a lot of cases, especially on a mobile phone where we don't have heavy resources. We can easily train this model on a typical laptop for a few hours, even...

Image dataset collection

For our experiment, we need the datasets for cars in good condition as well as in damaged condition. If you have a data source that adheres to the privacy policy, then this is a good place to start. Otherwise, we need to find a way to build our model on top of a dataset. There are multiple datasets that are publicly available. We need to start building our dataset if there is no existing reference of a similar data model because this could be a time-consuming task as well as an important step toward getting better results.

We are going to use a simple Python script to download images from Google. Just make sure that you filter images that can be reused. We don't encourage using pictures with non-reusable licenses.

With the Python script, we will pull out and save the images from Google, and then we will use a library to do the same task. This step...

Setting up a web application

We will use the Flask framework to build a simple application to detect the car's damage.

To learn more about Flask, please refer to https://www.fullstackpython.com/flask.html.

We are not going to go deeper into Flask basics here. Instead, we are simply adding our model with an existing file upload example from Flask.

The file's structure is shown in the following screenshot:

Here is a list of the contents in app.py:

import os
import glob
from classify import prediction
import tensorflow as tf
import thread
import time
from flask import Flask, render_template, request, redirect, url_for, send_from_directory,flash
from werkzeug import secure_filename
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads/'
app.config['ALLOWED_EXTENSIONS'] = set(['jpg', 'jpeg'])
app.config['SECRET_KEY&apos...

Summary

In this chapter, we have seen how we can build a model from scratch and train it using TensorFlow.

With this knowledge, we can start building more Android and iOS-based applications in the upcoming chapters.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mobile Artificial Intelligence Projects
Published in: Mar 2019Publisher: PacktISBN-13: 9781789344073
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Karthikeyan NG

Karthikeyan NG is the Head of Engineering and Technology at the Indian lifestyle and fashion retail brand. He served as a software engineer at Symantec Corporation and has worked with 2 US-based startups as an early employee and has built various products. He has 9+ years of experience in various scalable products using Web, Mobile, ML, AR, and VR technologies. He is an aspiring entrepreneur and technology evangelist. His interests lie in exploring new technologies and innovative ideas to resolve a problem. He has also bagged prizes from more than 15 hackathons, is a TEDx speaker and a speaker at technology conferences and meetups as well as guest lecturer at a Bengaluru University. When not at work, he is found trekking.
Read more about Karthikeyan NG

author image
Arun Padmanabhan

Arun Padmanabhan is a Machine Learning consultant with over 8 years of experience building end-to-end machine learning solutions and applications. Currently working with a couple of start-ups in the Financial and Insurance industries, he specializes in automating manual workflows using AI and creating Machine Vision and NLP applications. In past, he has led the data science team of a Singapore based product startup in the restaurant domain. He also has built stand-alone and integrated Machine Learning solutions in the Manufacturing, Shipping and e-commerce domains over the years. His interests are in research, development and applications of Artificial Intelligence and Deep Architectures.
Read more about Arun Padmanabhan

author image
Matt Cole

Matt R. Cole is a developer and author with 30 years' experience. Matt is the owner of Evolved AI Solutions, a provider of advanced Machine Learning/Bio-AI, Microservice and Swarm technologies. Matt is recognized as a leader in Microservice and Artificial Intelligence development and design. As an early pioneer of VOIP, Matt developed the VOIP system for NASA for the International Space Station and Space Shuttle. Matt also developed the first Bio Artificial Intelligence framework which completely integrates mirror and canonical neurons. In his spare time Matt authors books, and continues his education taking every available course in advanced mathematics, AI/ML/DL, Quantum Mechanics/Physics, String Theory and Computational Neuroscience.
Read more about Matt Cole