Skip to content

Commit 126a3f9

Browse files
first commit
0 parents  commit 126a3f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+19909
-0
lines changed

.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# exclude from GitHub's programming-language statistics
3+
/**/*.html linguist-vendored
4+
/**/*.ipynb linguist-vendored
5+
6+
# These files are text and should be normalized (Convert crlf => lf)
7+
*.gitattributes text
8+
.gitignore text
9+
*.md text
10+
11+
# Enable syntax highlighting for files with `.gitattributes` extensions.
12+
*.gitattributes linguist-language=gitattributes

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
.vs/
3+
4+
images/web_app.xcf
5+
flask_app/__pycache__/
6+
flask_app/app/__pycache__/
7+
flask_app/app/media-offline/*
8+
flask_app/app/static/images/banner.xcf
9+
flask_app/app/static/images/docker_network.xcf
10+
flask_app/app/static/images/target_blank.xcf
11+
flask_app/app/static/images/target_blank.png
12+
flask_app/*.proj
13+
flask_api/__pycache__/
14+
flask_api/api/utils/__pycache__/
15+
docker_archives/
16+
README.txt

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Surface Defect Detector
2+
3+
Welcome to this demonstration platform !
4+
5+
The goal is to demonstrate how to easily integrate a Tensorflow/Keras model into a microservice architecture to provide predictions on the fly.
6+
7+
The use case is surface defect detection from flat steel sheet images.
8+
9+
The architecture employed is made-up of 3 Docker containers as follows :
10+
11+
![](flask_app/app/static/images/docker_network.png)
12+
13+
The key element here is the webservice named ```defect-api-service```
14+
which is responsible for the generation of the prediction.
15+
Given an input image, it operates the surface defect detection
16+
and returns an augmented image and probability informations.
17+
18+
To illustrate its usage, the prediction webservice has been integrated into
19+
a basic web platform :
20+
21+
>```http://localhost/upload``` :
22+
select the image for anaysis<br />
23+
<img alt="upload page" src="images/upload.png" width="650px" />
24+
25+
<br />
26+
27+
>```http://localhost/prediction?filename=5e1c6b7da.jpg``` :
28+
result of the prediction as returned by ```defect-api-service```<br />
29+
<img alt="prediction page" src="images/prediction.png" width="650px" />
30+
31+
<br />
32+
33+
>```http://localhost/media/``` :
34+
list of media file<br />
35+
<img alt="media page" src="images/media.png" width="650px" />
36+
37+
For each image submitted for defect detection,
38+
the ```defect-api-service``` stores three different files :
39+
- the original image itself
40+
- a json representation of the prediction
41+
- the image with an overlayed contour
42+
of the detected defectuous area (if any)
43+
44+
<br />
45+
46+
For details on the model architecture and training
47+
as well as on what the reported probabilities do measure,
48+
please kindly refer to <a alt="jupyter notebook" href="https://htmlpreview.github.io/?https://github.com/aurelienmorgan/defect_detection_webservice/blob/master/notebook/model.html?uncache=654645">this walkthough Jupyter Notebook</a>.
49+
50+
<br />
51+
52+
53+
54+
55+
KEYWORDS :
56+
```Nginx```, ```uwsgi```, ```Gunicorn```,
57+
```container```, ```Docker```,
58+
```Flask```, ```REST api```, ```webservice```,
59+
```Tensorflow```, ```Keras```, ```U-Net```,
60+
```segmentation model```, ```data augmentation```,
61+
```OpenCV```

docker-compose.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
version: "3.7"
2+
3+
services:
4+
5+
defect-api-service:
6+
# build the container, looking into the Dockerfile at the bellow relative path
7+
build: ./flask_api
8+
container_name: flask_api
9+
image: flask_api:v0-phil
10+
restart: always
11+
# A place for us to define environment variables for the container
12+
environment:
13+
- PYTHONUNBUFFERED=1 # stdout not buffered
14+
- APP_NAME=MyFlaskApi
15+
- MEDIA_FOLDER=/api/api/media
16+
volumes:
17+
- media_volume:/api/api/media:rw
18+
# Exposes internal ports to other containers and services on the same network
19+
expose:
20+
- 9090
21+
22+
web_app:
23+
# build the container, looking into the Dockerfile at the bellow relative path
24+
build: ./flask_app
25+
container_name: flask_app
26+
image: flask_app:v0-p
27+
restart: always
28+
# A place for us to define environment variables for the container
29+
environment:
30+
- APP_NAME=MyFlaskApp
31+
- STATIC_FOLDER=/app/app/static
32+
- MEDIA_FOLDER=/app/app/media
33+
volumes:
34+
- static_volume:/app/app/static:ro
35+
- media_volume:/app/app/media:rw
36+
# Exposes internal ports to other containers and services on the same network
37+
expose:
38+
- 8080
39+
# declare service dependencies
40+
depends_on:
41+
- defect-api-service
42+
43+
http_server:
44+
build: ./http_server
45+
container_name: http_server
46+
image: http_server:v0-guk
47+
restart: always
48+
volumes:
49+
- static_volume:/home/web_app/static:ro
50+
- media_volume:/home/web_app/media:ro
51+
# expose ports to the outside world,
52+
# mappes port 80 on the host machine to port 80 of our Nginx container.
53+
ports:
54+
- "80:2020"
55+
depends_on:
56+
- web_app
57+
58+
volumes:
59+
static_volume:
60+
media_volume:

flask_api/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
api/__pycache__/
2+
api/utils/__pycache__/

flask_api/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Uthe Python 3.7.2 container image
2+
FROM python:3.7.2-stretch
3+
4+
# Set the working directory to "api"
5+
WORKDIR /api
6+
7+
# Copy the current directory contents into the container at /api
8+
ADD . /api
9+
10+
# Install the dependencies
11+
RUN pip install -r requirements.txt
12+
13+
14+
15+
# create an empty "/api/api/media/" folder prior to (volume creation &) parent permission allocation
16+
RUN mkdir -p /api/api/media && \
17+
chown -R www-data:www-data /api && \
18+
chown -R www-data:www-data /dev/shm
19+
#RUN stat /api
20+
#RUN cd api && stat media && cd ..
21+
22+
USER www-data
23+
24+
# Command to start Gunicorn
25+
ENTRYPOINT ["./gunicorn_starter.sh"]

flask_api/api/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import os
3+
4+
from flask import Flask
5+
6+
api = Flask(__name__)
267 Bytes
Binary file not shown.
294 Bytes
Binary file not shown.
2.49 KB
Binary file not shown.

0 commit comments

Comments
 (0)