-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (40 loc) · 1.68 KB
/
app.py
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
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import numpy as np
import tensorflow as tf
from PIL import Image # Required for some Streamlit versions
import matplotlib.pyplot as plt
# Example: Import TensorFlow model
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
# Example: Load ResNet50 model
model = ResNet50(weights='imagenet')
# Example: Function to preprocess image for ResNet50
def preprocess_image(img):
img = tf.image.resize(img, (224, 224)) # Resize to model input size
img = preprocess_input(img) # Preprocess according to model requirements
return img.numpy()
# Example: Function to perform deep learning-based analysis
def analyze_image(image):
# Preprocess image
processed_img = preprocess_image(image)
# Predict using the model
predictions = model.predict(np.expand_dims(processed_img, axis=0))
label = decode_predictions(predictions, top=1)[0][0]
return label
# Main Streamlit application
def main():
st.title('Deep Learning-Based PET Image Analysis')
# Sidebar for file upload and parameters
uploaded_file = st.file_uploader('Upload PET Image', type=['png', 'jpg', 'dicom'])
if uploaded_file is not None:
# Display uploaded image
image = np.array(Image.open(uploaded_file))
st.subheader('Uploaded PET Image')
st.image(image, caption='Uploaded PET Image', use_column_width=True)
# Perform deep learning-based analysis
if st.button('Analyze'):
prediction = analyze_image(image)
st.subheader('Analysis Result')
st.write(f'Prediction: {prediction}')
if __name__ == '__main__':
main()