Spaces:
Sleeping
Sleeping
File size: 1,970 Bytes
c373b1f 173bba6 c373b1f 173bba6 c373b1f 173bba6 c373b1f 173bba6 1325510 173bba6 c373b1f 173bba6 c373b1f 173bba6 c373b1f 173bba6 09dc8fd c373b1f 173bba6 c373b1f 173bba6 | 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 | import numpy as np
import os
from tensorflow.keras.models import load_model # type: ignore
from tensorflow.keras.preprocessing import image # type: ignore
from tensorflow.keras.layers import Flatten # type: ignore
from tensorflow.keras.applications.densenet import preprocess_input# type: ignore
import tensorflow as tf
from flask import Flask , request, render_template
#from werkzeug.utils import secure_filename
#from gevent.pywsgi import WSGIServer
app = Flask(__name__)
basepath = os.path.dirname(__file__)
modelpath = os.path.join(basepath,'uploads',"best1den.keras")
model = load_model(modelpath)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/service')
def service():
return render_template('service.html')
@app.route('/predict',methods = ['GET','POST'])
def upload():
if request.method == 'POST':
f = request.files['image']
#print("current path")
basepath = os.path.dirname(__file__)
print("current path", basepath)
filepath = os.path.join(basepath,'uploads',f.filename)
print("upload folder is ", filepath)
f.save(filepath)
img=image.load_img(filepath,target_size=(224,224))
img=image.img_to_array(img)
img=img.reshape((1,img.shape[0],img.shape[1],img.shape[2]))
img=preprocess_input(img)
pred=model.predict(img)
pred=pred.flatten()
pred=list(pred)
n=max(pred)
val_dict={0: 'Aircraft Carrier',
1: 'Bulkers',
2: 'Car Carrier',
3: 'Container Ship',
4: 'Cruise',
5: 'DDG',
6: 'Recreational',
7: 'Sailboat',
8: 'Submarine',
9: 'Tug'}
result=val_dict[pred.index(n)]
print(result)
text = "the Ship Category is " + result
return text
if __name__ == '__main__':
app.run(debug = True)
|