demo_0.1 / app.py
219x5a05k4gprecacin's picture
Update app.py
c72564c verified
import cv2
import numpy as np
import streamlit as st
import tensorflow as tf
from PIL import Image
from tensorflow.keras.preprocessing import image
from keras.preprocessing.image import img_to_array
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2,preprocess_input as mobilenet_v2_preprocess_input
cnn = tf.keras.models.load_model("saved_model/cnn_brain_model_9_11.h5")
resnet = tf.keras.models.load_model("saved_model/resnet_brain_model_9_11.h5")
vgg = tf.keras.models.load_model("saved_model/vgg_brain_model_9_11.h5")
### load file
uploaded_file = st.file_uploader("Choose a image file", type="jpg")
map_dict = {0: 'demented',
1: 'glioma',
2: 'healthy',
3: 'meningioma',
4: 'pituitary'}
if uploaded_file is not None:
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
opencv_image = cv2.imdecode(file_bytes, 1)
image = Image.fromarray(opencv_image, 'RGB')
image = image.resize((200, 200))
image=np.array(image)
input_img = np.expand_dims(image, axis=0)
st.image(image, channels="RGB")
img=[]
img.append(input_img)
img = np.array(img)
print(img.shape)
img = img.astype(np.float32) / 255.0
Genrate_pred = st.button("Generate Prediction")
if Genrate_pred:
prediction = cnn.predict(img[0]).argmax()
st.title("Predicted Label for the image by cnn model is {}".format(map_dict [prediction]))
prediction = resnet.predict(img[0]).argmax()
st.title("Predicted Label for the image by resnet model is {}".format(map_dict [prediction]))
prediction = vgg.predict(img[0]).argmax()
st.title("Predicted Label for the image by vgg model is {}".format(map_dict [prediction]))