-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
43 lines (39 loc) · 1.34 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
import streamlit as st
from PIL import Image,ImageOps
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
from tensorflow.keras import preprocessing
from tensorflow.keras.models import load_model
from tensorflow.keras.activations import sigmoid
import os
import h5py
st.header('Malaria Cell Detector')
def main():
file_uploaded = st.file_uploader('Choose the file', type = ['jpg','png','jpeg'])
if file_uploaded is not None:
image = Image.open(file_uploaded)
figure = plt.figure()
plt.imshow(image)
plt.axis('off')
result = predict_class(image)
st.write(result)
st.pyplot(figure)
def predict_class(image):
classifier_model = tf.keras.models.load_model(r'/content/my_model.hdf5')
shape = ((64,64,3))
model = tf.keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)])
test_image = image.resize((64,64))
test_image = preprocessing.image.img_to_array(test_image)
test_image = test_image / 255.0
test_image = np.expand_dims(test_image, axis = 0)
class_names = ['Parasitized','Uninfected']
predictions = model.predict(test_image)
scores = tf.nn.sigmoid(predictions[0])
scores = scores.numpy()
image_class = class_names[np.argmax(scores)]
result = "The image uploaded is: {}".format(image_class)
return result
if __name__ == "__main__":
main()