ilhamstoked commited on
Commit
feea1a4
1 Parent(s): d70f44c

Upload 2 files

Browse files
Files changed (2) hide show
  1. InceptionResNetV2Skripsi.tflite +3 -0
  2. app1.py +67 -0
InceptionResNetV2Skripsi.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ce9b335d23bb9811adffe070040def6a0b8feecff69e345c0d1c16364804bfb
3
+ size 56233680
app1.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+
5
+ # Load TensorFlow Lite model
6
+ interpreter = tf.lite.Interpreter(model_path="InceptionResNetV2Skripsi.tflite")
7
+ interpreter.allocate_tensors()
8
+
9
+ # Get input and output tensors
10
+ input_details = interpreter.get_input_details()
11
+ output_details = interpreter.get_output_details()
12
+
13
+ # Define a function to resize the input image
14
+ def resize_image(image):
15
+ # Resize the image to 150x150 pixels
16
+ resized_image = tf.image.resize(image, [150, 150])
17
+ return resized_image.numpy()
18
+
19
+ # Define a function to run inference on the TensorFlow Lite model
20
+ def classify_image(image):
21
+ # Pre-process the input image
22
+ resized_image = resize_image(image)
23
+ input_data = np.expand_dims(resized_image, axis=0).astype(np.float32)
24
+ interpreter.set_tensor(input_details[0]['index'], input_data)
25
+
26
+ # Run inference
27
+ with st.spinner('Classifying...'):
28
+ interpreter.invoke()
29
+
30
+ # Get the output probabilities
31
+ output_data = interpreter.get_tensor(output_details[0]['index'])
32
+ return output_data[0]
33
+
34
+ # Define the labels for the 7 classes
35
+ labels = ['akiec', 'bcc', 'bkl', 'df', 'mel', 'nv', 'vasc']
36
+
37
+ from PIL import Image
38
+ # Define the main Streamlit app
39
+ def main():
40
+ st.title("Skin Cancer Classification")
41
+
42
+ st.write("Please note that this model still has room for academic revision as it can only classify the following 7 classes")
43
+ st.text("'akiec' - squamous cell carcinoma (actinic keratoses dan intraepithelial carcinoma),")
44
+ st.text("'bcc' - basal cell carcinoma, 'bkl' - benign keratosis (serborrheic keratosis),")
45
+ st.text("'df' - dermatofibroma, 'nv' - melanocytic nevi, 'mel' - melanoma,")
46
+ st.text("'vasc' - vascular skin lesions (Cherry Angiomas, Angiokeratomas, Pyogenic Granulomas.")
47
+ 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. ")
48
+
49
+ # Get the input image from the user
50
+ image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
51
+
52
+ # Show the input image
53
+ if image is not None:
54
+ image = np.array(Image.open(image))
55
+ st.image(image, width=150)
56
+
57
+ # Run inference on the input image
58
+ probs = classify_image(image)
59
+
60
+ # Display the top 3 predictions
61
+ top_3_indices = np.argsort(probs)[::-1][:3]
62
+ st.write("Top 3 predictions:")
63
+ for i in range(3):
64
+ st.write("%d. %s (%.2f%%)" % (i + 1, labels[top_3_indices[i]], probs[top_3_indices[i]] * 100))
65
+
66
+ if __name__ == '__main__':
67
+ main()