Using artificial intelligence to differentiate between human and synthetic hair wigs with Amazon…
Tags: humanhairwigs, artificialintelligen, imageclassification, sagemaker
Published: 2020-06-21 11:54:23

---
title: Using artificial intelligence to differentiate between human and synthetic hair wigs with Amazon…
published: false
date: 2020-05-02 07:19:10 UTC
tags: humanhairwigs,artificialintelligen,imageclassification,sagemaker
canonical_url: 
published: true
---

### Using artificial intelligence to differentiate between human and synthetic hair wigs with Amazon SageMaker

![](https://cdn-images-1.medium.com/max/1024/1*3q79lx7S4E6yRetKAx-BDw.png)

The hair extensions industry is a multi-billion dollar global industry. [According to China Customs](https://www.scmp.com/business/china-business/article/3011657/chinas-wig-capital-has-designs-africa-us-tariffs-loom), China’s wig exports reached excess of $2 billion dollar, with US being the largest destination. However, wig manufacturers in China are moving focus from US to Africa.

![](https://cdn-images-1.medium.com/max/972/1*rFy9LzT4WCS1HKhZTePw_Q.jpeg)

### Customer Problem Discovery

After speaking with a handful of ladies, one of the major challenges experienced by shoppers is **Trust** which is rooted in vendors selling synthetic hair (low quality) and human hair. Also speaking with vendors, it turns out that differentiating between both synthetic hair and human hair wigs can be challenging. One only knows when the hair is made or wig is bought and used. This appears like a classic task for [Image Classification](https://www.tensorflow.org/tutorials/images/classification).

### Implementation

In this tutorial, we will train an image classification model using [Amazon SageMaker built-in algorithm](https://docs.aws.amazon.com/sagemaker/latest/dg/image-classification.html). Images are organized in folders named for corresponding classes, **human-hair** and **synthetic-hair**.

```
images\_to\_classify

├── human-hair
│ ├── 1.jpg
│ ├── 2.jpg
| ├── 3.jpg
│ └── . . .
└── synthetic-hair
│ ├── 1.jpg
│ ├── 2.jpg
│ ├── 3.jpg
│ ├── . . .
└── . . .
```

The [sample dataset](https://gram-to-store-images.s3-eu-west-1.amazonaws.com/dataset/wigs/) was scraped from [GlamorousHair.com](https://www.glamorousremihair.com/) and is available on [Amazon S3](https://aws.amazon.com/s3/).

![](https://cdn-images-1.medium.com/max/1024/1*gonYgs08DAwcUEq7YYpXmQ.png)<figcaption>Synthetic and Human Hair wig images. Courtesy: GlamorousHair.com</figcaption>

#### Hypothesis

If we are able to differentiate between **synthetic** and **human hair** wigs with images right before customers complete their purchase, then we can help customers can build trust with hair vendors. We will know that we succeeded if we achieve **65%** validation accuracy with our machine learning model.

Jupyter Notebook available below:

[OElesin/aws-samples](https://github.com/OElesin/aws-samples/blob/master/sagemaker/HumanHairImageClassification.ipynb)

{% youtube FZX4F5ty5sw %}

#### Hypothesis Validation

Based on the acceptance criterion defined above hypothesis, we can proceed to deploy our model into production. The deployment is completed with the Amazon SageMaker Endpoint.

First run, 10 epochs, with the following accuracy metrics:

- Train accuracy: **1.000000**
- Validation-accuracy: **0.937500**

We also trained on Spot instances saving **69.8%** of the cost.

Further model improvements, [Amazon SageMaker Automatic Model Tuning](https://docs.aws.amazon.com/sagemaker/latest/dg/automatic-model-tuning.html) will be used. For real-life, constant retraining of the model and evaluation with Human-In-the-Loop with [Amazon Augmented AI (Amazon A2I](https://aws.amazon.com/augmented-ai/)).

### Conclusion

This is my first recipe with [Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-studio.html). A next step might be to train an [image segmentation model](https://docs.aws.amazon.com/sagemaker/latest/dg/semantic-segmentation.html) to identify hair quality at pixel level.

I hope to share more with you. If you enjoyed reading this, kindly share and comment. You can reach me via [email](mailto:elesin.olalekan@gmail.com), follow me on [Twitter](https://twitter.com/elesinOlalekan) or connect with me on [LinkedIn](https://www.linkedin.com/in/elesinolalekan/). Can’t wait to hear from you!!