-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (44 loc) · 1.33 KB
/
app.py
File metadata and controls
51 lines (44 loc) · 1.33 KB
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
from flask import Flask, render_template, request
import numpy as np
from PIL import Image
from keras.models import load_model
import os
app = Flask(__name__)
path_to_model = 'human_action.h5'
V_model = load_model(path_to_model)
def read_image(fn):
image = Image.open(fn).convert('RGB')
return np.asarray(image.resize((224, 224)))
def test_predict(test_image):
result = V_model.predict(np.asarray([read_image(test_image)]))
itemindex = np.where(result == np.max(result))
prediction = itemindex[1][0]
label_map = {
0: "Sitting",
1: "Drinking",
2: "Calling",
3: "Sleeping",
4: "Drinking",
5: "Clapping",
6: "Dancing",
7: "Cycling",
8: "Calling",
9: "Laughing",
10: "Eating",
11: "Fighting",
12: "Listening_to_music",
13: "Running",
14: "Exting"
}
prediction = label_map[prediction]
return prediction
@app.route('/', methods=["GET","POST"])
def home():
if request.method=="POST":
image_file = request.files.get('image')
if image_file:
prediction = test_predict(image_file)
return render_template("index.html", result=prediction)
else:
return render_template("index.html", result="No image uploaded")
return render_template("index.html")