-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
65 lines (51 loc) · 1.77 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
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 12 11:53:50 2021
@author: user
"""
import os
import tensorflow as tf
import numpy as np
from keras.models import load_model
from keras.optimizers import Adam
from keras.initializers import RandomNormal
from keras.models import Model
from keras.models import Input
from keras.layers import Conv2D
from keras.layers import ReLU
from keras.layers import Activation
from keras.layers import BatchNormalization
from os import listdir
from numpy import asarray
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
from flask import Flask, request
from flask import render_template
# from keras.backend import set_session
app = Flask(__name__)
UPLOAD_FOLDER = 'D:\\Paritosh\\_workspace\\webapp\\static'
global model
model = load_model("c_model_043080.h5")
# @app.route('/')
# def welc_msg():
# return "Stairway to heaven..."
@app.route('/', methods=['GET', 'POST'])
def upload_predict():
if request.method == 'POST':
image_file = request.files['image']
if image_file:
image_location = os.path.join(
UPLOAD_FOLDER,
image_file.filename
)
image_file.save(image_location)
img = load_img(os.path.join(UPLOAD_FOLDER, image_file.filename))
image_arr = img_to_array(img)
image_arr = image_arr[:,:,0]/255.0
image_arr = image_arr.reshape((1,256,256,1))
pred = model.predict(image_arr)
pred = np.around(pred, decimals=3)
return render_template("index.html", prediction=pred)
return render_template("index.html", prediction=0)
if __name__ == '__main__':
app.run(host='0.0.0.0')