File size: 1,181 Bytes
927adb7
392b986
927adb7
392b986
927adb7
392b986
 
927adb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392b986
927adb7
 
392b986
927adb7
392b986
927adb7
 
392b986
 
 
927adb7
392b986
 
927adb7
392b986
 
 
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
from PIL import Image
import tensorflow as tf
import numpy as np
#from google.colab import files

#model_path = 'final_teath_classifier.h5'
# Load the model
model = tf.keras.models.load_model(model_path)

def preprocess_image(image: Image.Image) -> np.ndarray:
    # Resize the image to match input size
    image = image.resize((256, 256))
    # Convert image to array and preprocess input
    img_array = np.array(image) / 255.0
    # Add batch dimension
    img_array = np.expand_dims(img_array, axis=0)
    return img_array

def predict_image(image_path):
    img = Image.open(image_path)
    # Preprocess the image
    img_array = preprocess_image(img)
    predictions = model.predict(img_array)
    predicted_class = np.argmax(predictions)
    if predicted_class == 0:
      predict_label = "Clean"
    else:
      predict_label = "Carries"


    return predict_label,predictions.flatten()
# Upload the image
#uploaded = files.upload()

# Get the uploaded image file name
#image_path = list(uploaded.keys())[0]

predict_label, logits = predict_image(image_path)
print("Predicted class:", predict_label)
print("Evaluate:", ', '.join(f"{logits*100:.4f}%" for logits in logits))