File size: 1,494 Bytes
3982870
 
24bab8a
 
 
343c9a4
19e570f
3982870
a90efc8
3982870
5c7c640
3982870
 
 
 
 
 
 
 
 
86f5b35
 
343c9a4
 
 
 
 
 
 
 
24bab8a
2b4cccf
343c9a4
 
 
8904fa3
 
 
 
 
 
 
 
 
 
 
 
 
343c9a4
 
8904fa3
 
 
 
3982870
8904fa3
 
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
54
55
56
57
import streamlit as st
import tensorflow as tf
import cv2
import numpy as np
from PIL import Image, ImageOps
import imageio.v3 as iio
#from io import BytesIO

@st.cache_resource()
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", type= ['png', 'jpg'])

# def model_prediction(image, model):
#     resize = tf.image.resize(image, (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

def model_prediction(image, model):
    
    item = cv2.resize(image,dsize=(256,256), interpolation=cv2.INTER_CUBIC)
    yhat = model.predict(np.expand_dims(item/255, 0))
    if(yhat>0.5):
        result = "Prediction is loose"
    else:
        result = "Prediction is control"
    return result


def on_click():
    if file is None:
        st.text("Please upload an image file")
    else:
        image = Image.open(file)
        st.image(image, use_column_width=True)
        img = iio.imread(file)
        predictions = model_prediction(img, model)
        st.write(prediction)
        print(
            "This image most likely belongs to {}."
            .format(prediction)
)

st.button('Predict', on_click=on_click)