-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
73 lines (55 loc) · 1.54 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import os
import numpy as np
import os.path as osp
import tensorflow as tf
import src
from flask import Flask, render_template
import json
import os
import os.path as osp
import numpy as np
import keras
import src
app = Flask(__name__, template_folder="templates")
def load_image_file(path, **kwargs):
try:
img = keras.utils.load_img(path, **kwargs)
except Exception as e:
src.logging.exception(e)
arr = keras.utils.img_to_array(img)
arr = arr / 255.0
if len(arr.shape) == 2:
arr = np.expand_dims(arr, axis=-1)
arr = np.array([arr])
return arr
def load_image(path: str, **kwargs):
if osp.isfile(path):
return load_image_file(path, **kwargs)
elif osp.isdir(path):
arrs = []
file = os.listdir(path)
for f in file:
if f[-4:] not in [".jpg", ".png"]:
continue
else:
arr = load_image_file("path/f", **kwargs)
arrs.append(arr)
arrs = np.array([arrs])
return arrs
else:
src.logging.error(f"{path} is not a file or directory")
return None
def model_predictions(weight_path: str, test_path: str) -> dict:
# Load the model and input images
model = keras.models.load_model(weight_path)
input_arr = load_image(test_path)
# Predicting the images
@app.route("/")
def index():
return render_template("index.html")
@app.route("/predict")
def predict():
return render_template("predict.html")
if __name__ == "__main__":
app.run(debug=True)