|
import os |
|
import numpy as np |
|
import tensorflow as tf |
|
from tensorflow.keras.models import load_model |
|
import streamlit as st |
|
|
|
|
|
st.header('Dental Classification CNN Model') |
|
|
|
|
|
class_names = ['Calculus', 'Dental Caries', 'Gingivitis', 'Hypodontia', 'Tooth Discoloration'] |
|
|
|
|
|
model = load_model('model.h5') |
|
|
|
def classify_images(image): |
|
|
|
input_image = tf.keras.utils.img_to_array(image) |
|
input_image = tf.image.resize(input_image, (180, 180)) |
|
input_image_exp_dim = tf.expand_dims(input_image, axis=0) |
|
|
|
|
|
predictions = model.predict(input_image_exp_dim) |
|
result = tf.nn.softmax(predictions[0]) |
|
|
|
|
|
outcome = f'The image belongs to {class_names[np.argmax(result)]} with a score of {np.max(result) * 100:.2f}%' |
|
return outcome |
|
|
|
|
|
uploaded_file = st.file_uploader('Upload an Image', type=['png', 'jpg', 'jpeg']) |
|
if uploaded_file is not None: |
|
|
|
image = tf.keras.utils.load_img(uploaded_file, target_size=(256, 256)) |
|
|
|
|
|
st.image(uploaded_file, width=200) |
|
|
|
|
|
result = classify_images(image) |
|
st.markdown(result) |