Mister56's picture
Initial commit
b352fc1 verified
raw
history blame
1.19 kB
import os
import keras
from tensorflow.keras.models import load_model # type: ignore
import streamlit as st
import tensorflow as tf
import numpy as np
st.header('Dental Classification CNN Model')
#class_names = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip']
class_names = ['Calculus', 'Dental Caries', 'Gingivitis', 'Hypodontia', 'Tooth discoloration']
model = load_model('model2.keras')
def classify_images(image_path):
input_image = tf.keras.utils.load_img(image_path, target_size=(256,256))
input_image_array = tf.keras.utils.img_to_array(input_image)
input_image_exp_dim = tf.expand_dims(input_image_array,0)
predictions = model.predict(input_image_exp_dim)
result = tf.nn.softmax(predictions[0])
outcome = 'The Image belongs to ' + class_names[np.argmax(result)] + ' with a score of '+ str(np.max(result)*100)
return outcome
uploaded_file = st.file_uploader('Upload an Image')
if uploaded_file is not None:
with open(os.path.join('upload', uploaded_file.name), 'wb') as f:
f.write(uploaded_file.getbuffer())
st.image(uploaded_file, width = 200)
st.markdown(classify_images(uploaded_file))