File size: 1,337 Bytes
fa27c09
 
68833be
 
 
fa27c09
68833be
fa27c09
 
68833be
 
fa27c09
68833be
566add7
fa27c09
68833be
 
 
27913d2
68833be
 
 
fa27c09
 
68833be
 
 
fa27c09
 
68833be
 
fa27c09
68833be
 
fa27c09
68833be
 
fa27c09
68833be
 
 
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
import os
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
import streamlit as st

# Title of the application
st.header('Dental Classification CNN Model')

# Class names
class_names = ['Calculus', 'Dental Caries', 'Gingivitis', 'Hypodontia', 'Tooth Discoloration']

# Load the model
model = load_model('model.h5')

def classify_images(image):
    # Resize and preprocess the image
    input_image = tf.keras.utils.img_to_array(image)
    input_image = tf.image.resize(input_image, (180, 180))  # Resize to the expected input size
    input_image_exp_dim = tf.expand_dims(input_image, axis=0)

    # Make predictions
    predictions = model.predict(input_image_exp_dim)
    result = tf.nn.softmax(predictions[0])
    
    # Prepare the outcome message
    outcome = f'The image belongs to {class_names[np.argmax(result)]} with a score of {np.max(result) * 100:.2f}%'
    return outcome

# Upload the file
uploaded_file = st.file_uploader('Upload an Image', type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
    # Read the uploaded image
    image = tf.keras.utils.load_img(uploaded_file, target_size=(256, 256))
    
    # Display the image
    st.image(uploaded_file, width=200)

    # Classify the image and display the result
    result = classify_images(image)
    st.markdown(result)