|
import streamlit as st |
|
import numpy as np |
|
import tensorflow as tf |
|
|
|
|
|
interpreter = tf.lite.Interpreter(model_path="InceptionResNetV2Skripsi.tflite") |
|
interpreter.allocate_tensors() |
|
|
|
|
|
input_details = interpreter.get_input_details() |
|
output_details = interpreter.get_output_details() |
|
|
|
|
|
def resize_image(image): |
|
|
|
resized_image = tf.image.resize(image, [150, 150]) |
|
return resized_image.numpy() |
|
|
|
|
|
def classify_image(image): |
|
|
|
resized_image = resize_image(image) |
|
input_data = np.expand_dims(resized_image, axis=0).astype(np.float32) |
|
interpreter.set_tensor(input_details[0]['index'], input_data) |
|
|
|
|
|
with st.spinner('Classifying...'): |
|
interpreter.invoke() |
|
|
|
|
|
output_data = interpreter.get_tensor(output_details[0]['index']) |
|
return output_data[0] |
|
|
|
|
|
labels = ['akiec', 'bcc', 'bkl', 'df', 'mel', 'nv', 'vasc'] |
|
|
|
from PIL import Image |
|
|
|
def main(): |
|
st.title("Skin Cancer Classification") |
|
|
|
st.write("Please note that this model still has room for academic revision as it can only classify the following 7 classes") |
|
st.text("'akiec' - squamous cell carcinoma (actinic keratoses dan intraepithelial carcinoma),") |
|
st.text("'bcc' - basal cell carcinoma, 'bkl' - benign keratosis (serborrheic keratosis),") |
|
st.text("'df' - dermatofibroma, 'nv' - melanocytic nevi, 'mel' - melanoma,") |
|
st.text("'vasc' - vascular skin lesions (Cherry Angiomas, Angiokeratomas, Pyogenic Granulomas.") |
|
st.write("Due to imperfection of the model and a room of improvement for the future, if the probabilities shown are less than 70%, the skin is either healthy or the input image is unclear. This means that the model can be the first diagnostic of your skin illness. As precautions for your skin illness, it is better to do consultation with dermatologist. ") |
|
|
|
|
|
image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
if image is not None: |
|
image = np.array(Image.open(image)) |
|
st.image(image, width=150) |
|
|
|
|
|
probs = classify_image(image) |
|
|
|
|
|
top_3_indices = np.argsort(probs)[::-1][:3] |
|
st.write("Top 3 predictions:") |
|
for i in range(3): |
|
st.write("%d. %s (%.2f%%)" % (i + 1, labels[top_3_indices[i]], probs[top_3_indices[i]] * 100)) |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|