# Madein4@Polito - Autoencoder-based Defect Detection

A REST API for defect detection, which leverages an autoencoder to discriminate between normal and defective images.

The code is based on Python3 and uses `tensorflow` and `keras` to implement the autoencoder, and `cherrypy` for the REST API. The current version of the code is using an autoencoder trained on different images with respect to the final ones in terms of camera used, positioning, etc. Therefore, inference times and memory occupation might not represent the final ones.

### Prerequisites

The first step consists in installing the required Python modules using `pip`:

```
pip install -r requirements.txt
```


### Usage

1. Start the server running the server.py script in order to activate the application for image classification.

```
python server.py
```

2. Run the client script to send a request to the application hosted on the server and classify an image.
The application will output
- the classification label ("NORMAL"/"DEFECT") for that image
- the reconstruction_score which can be interpreted as a measure of defect severity: the higher the score, the more likely it is the spot has a defect. (Reconstruction score for normal images in the test set is lower than 50)

For testing purposes, few normal and defective images are available in the test_images folder.

```
python client.py -i image_file_path
```
