File size: 1,077 Bytes
3982870
 
 
 
 
 
5c7c640
3982870
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
from PIL import Image

@st.cache(allow_output_mutation=True)
def load_model():
    model=tf.keras.models.load_model('./hip_impant_model.h5')
    return model
with st.spinner('Model is being loaded..'):
    model=load_model()

st.write("""
         # Image Classification
         """
         )

file = st.file_uploader("Upload an X-ray image")
import cv2
from PIL import Image, ImageOps
import numpy as np
st.set_option('deprecation.showfileUploaderEncoding', False)
def model_prediction(img, model):
    resize = tf.image.resize(img, (256,256))
    yhat = model.predict(np.expand_dims(resize/255, 0))
    if(yhat>0.5):
        result = "Prediction is loose"
    else:
        result = "Prediction is control"
    return result
        
if file is None:
    st.text("Please upload an image file")
else:
    image = Image.open(file)
    st.image(image, use_column_width=True)
    predictions = mode_prediction(image, model)
    st.write(prediction)
    print(
    "This image most likely belongs to {}."
    .format(prediction)
)