-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify.py
54 lines (44 loc) · 1.51 KB
/
classify.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
'''
NAME : OMONIYI TEMIDAYO ANDREW
EMAIL: [email protected], [email protected]
NO: +2348166220117
TOPIC : MALARIA CLASSIFICATION USING AI
TEAM : TEAM WAKANDA
'''
import tensorflow as tf
import numpy as np
import io
#import cv2
from PIL import Image
import base64
from tensorflow.keras import backend as k
from tensorflow.keras.models import Sequential
from tensorflow.keras.models import load_model # used for loading model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import img_to_array, load_img
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
#Load the model
print('Loading...')
model = load_model('malaria_model_summit.h5')
print("Model Loaded***")
def converter(value):
if value == 0:
return "infected"
else:
return "uninfected"
def predict(image1):
image = load_img(image1, target_size=(224, 224))
# convert the image pixels to a numpy array
image = img_to_array(image)
# reshape data for the model
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
# prepare the image for the VGG model
#image = preprocess_input(image)
# predict the probability across all output classes
yhat = model.predict(image)
# convert the probabilities to class labels
print('Input', image)
print('Output_binary', yhat*100,'%');
print('Output', converter(np.argmax(yhat)));
return converter(np.argmax(yhat))