initial
This commit is contained in:
11
part3/Dockerfile
Normal file
11
part3/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM python:3.11
|
||||
|
||||
RUN pip install tensorflow==2.15
|
||||
RUN pip install Flask==3.0
|
||||
RUN pip install pillow==12.0.0
|
||||
|
||||
COPY vgg16Variant.keras /vgg16Variant.keras
|
||||
COPY api.py /api.py
|
||||
|
||||
|
||||
CMD ["python", "api.py"]
|
||||
56
part3/api.py
Normal file
56
part3/api.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from flask import Flask, request
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
app = Flask(__name__)
|
||||
model = tf.keras.models.load_model('vgg16Variant.keras')
|
||||
|
||||
@app.route('/summary', methods=['GET'])
|
||||
def model_info():
|
||||
return {
|
||||
"version": "vgg16Variant",
|
||||
"name": "Katrina_damage",
|
||||
"description": "Classify satellite images of buildings in the aftermath of a hurricane into 'damage' or 'no_damage' categories",
|
||||
"number_of_parameters": 16812353
|
||||
}
|
||||
# def model_info():
|
||||
# return {
|
||||
# "version": "leNet5Variant",
|
||||
# "name": "Katrina_damage",
|
||||
# "description": "Classify satellite images of buildings in the aftermath of a hurricane into 'damage' or 'no_damage' categories",
|
||||
# "number_of_parameters": 2601153
|
||||
# }
|
||||
|
||||
@app.route('/inference', methods=['POST'])
|
||||
def upload_file():
|
||||
|
||||
# check if the post request has the file part
|
||||
if 'image' not in request.files:
|
||||
# if the user did not pass the image under `image`, we don't know what they are
|
||||
# don't, so return an error.
|
||||
return {"error": "Invalid request; pass a binary image file as a multi-part form under the image key."}, 404
|
||||
# get the data
|
||||
data = request.files['image']
|
||||
# do something with data...
|
||||
print(data) # apparently this is a FileStorage object??
|
||||
# Googled how to deal with it and got the following code to turn it into a numpy array
|
||||
image_bytes = data.read()
|
||||
image_stream = io.BytesIO(image_bytes)
|
||||
|
||||
with Image.open(image_stream).convert("RGB") as pil_image:
|
||||
data = np.asarray(pil_image)
|
||||
|
||||
print(data.shape)
|
||||
data = data / np.max(data)
|
||||
data = data.reshape(1,128,128,3)
|
||||
prediction = model.predict(data)[0][0]
|
||||
if prediction < 0.5:
|
||||
return {"prediction": "damage"}
|
||||
else:
|
||||
return {"prediction": "no_damage"}
|
||||
|
||||
# start the development server
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0')
|
||||
7
part3/docker-compose.yml
Normal file
7
part3/docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
version: '3.8' # or a newer version like '3.9'
|
||||
|
||||
services:
|
||||
inference_server:
|
||||
image: adipu24/project02:latest # Replace with your image name and tag
|
||||
ports:
|
||||
- "5000:5000" # Maps host port 5000 to container port 5000
|
||||
3
part3/vgg16Variant.keras
Normal file
3
part3/vgg16Variant.keras
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:56eea1bd56e5c37f3db197e044a4c1307d894e8e6f82bbdd8286184d5c42f123
|
||||
size 201873648
|
||||
Reference in New Issue
Block a user