-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (25 loc) · 861 Bytes
/
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
from flask import Flask, request,render_template
import os
from PIL import Image
import cv2
import numpy as np
import torch
from Image_Classifier import Image_Classifier
app = Flask(__name__)
@app.route('/')
def predict_image():
data =request.files['imagefile']
img = Image.open(request.files['imagefile'])
img = np.array(img)
img = cv2.resize(img,(64,64))
img = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
preds = model.forward(torch.Tensor(img).unsqueeze(0).permute(0, 3, 1, 2))
predict = np.argmax(preds.detach().numpy(), axis=1)
result = 'The image shows a :: '+str(predict[0])
return result
if __name__ == '__main__':
model = Image_Classifier()
PATH = "/home/surbhi/Desktop/Vision_Code/Classification/model.pt"
model = torch.load(PATH)
model.eval()
app.run(debug=True)