Spaces:
Sleeping
Sleeping
Updated app.py with new layout and new pictures
Browse files
app.py
CHANGED
@@ -114,36 +114,52 @@ def calculate_dice_coefficient(image1, image2):
|
|
114 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
115 |
st.set_page_config(layout='wide')
|
116 |
ds = load_dataset('ahishamm/combined_masks',split='train')
|
117 |
-
s1 = ds[
|
118 |
-
s2 = ds[
|
119 |
-
s3 = ds[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
img = image_select(
|
121 |
label="Select a Skin Lesion Image",
|
122 |
images=[
|
123 |
-
s1,s2,s3
|
124 |
],
|
125 |
-
captions=["sample 1","sample 2","sample 3"],
|
126 |
return_value='index'
|
127 |
)
|
|
|
128 |
processor = AutoProcessor.from_pretrained('ahishamm/skinsam')
|
129 |
model = AutoModelForMaskGeneration.from_pretrained('ahishamm/skinsam_focalloss_base_combined')
|
130 |
model.to(device)
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
133 |
predicted_mask = generate_image(predicted_mask_array)
|
134 |
-
result_image = show_mask(ds[img]['image'],predicted_mask_array)
|
|
|
135 |
with st.container():
|
136 |
-
|
137 |
-
with
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
114 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
115 |
st.set_page_config(layout='wide')
|
116 |
ds = load_dataset('ahishamm/combined_masks',split='train')
|
117 |
+
s1 = ds[3]['image']
|
118 |
+
s2 = ds[4]['image']
|
119 |
+
s3 = ds[5]['image']
|
120 |
+
s4 = ds[6]['image']
|
121 |
+
s1_label = ds[3]['label']
|
122 |
+
s2_label = ds[4]['label']
|
123 |
+
s3_label = ds[5]['label']
|
124 |
+
s4_label = ds[6]['label']
|
125 |
+
image_arr = [s1,s2,s3,s4]
|
126 |
+
label_arr = [s1_label,s2_label,s3_label,s4_label]
|
127 |
img = image_select(
|
128 |
label="Select a Skin Lesion Image",
|
129 |
images=[
|
130 |
+
s1,s2,s3,s4
|
131 |
],
|
132 |
+
captions=["sample 1","sample 2","sample 3","sample 4"],
|
133 |
return_value='index'
|
134 |
)
|
135 |
+
#testing with an uploaded image
|
136 |
processor = AutoProcessor.from_pretrained('ahishamm/skinsam')
|
137 |
model = AutoModelForMaskGeneration.from_pretrained('ahishamm/skinsam_focalloss_base_combined')
|
138 |
model.to(device)
|
139 |
+
#uploaded_file = st.file_uploader("Choose a file",type=['jpg','jpeg','png'])
|
140 |
+
#p = get_bounding_box(np.array(ds[img]['label']))
|
141 |
+
p = get_bounding_box(np.array(label_arr[img]))
|
142 |
+
#predicted_mask_array = get_output(ds[img]['image'],p)
|
143 |
+
predicted_mask_array = get_output(image_arr[img],p)
|
144 |
+
#predicted_mask = generate_image(predicted_mask_array)
|
145 |
predicted_mask = generate_image(predicted_mask_array)
|
146 |
+
#result_image = show_mask(ds[img]['image'],predicted_mask_array)
|
147 |
+
result_image = show_mask(image_arr[img],predicted_mask_array)
|
148 |
with st.container():
|
149 |
+
tab1, tab2 = st.tabs(['Visualizations','Metrics'])
|
150 |
+
with tab1:
|
151 |
+
col1, col2, col3 = st.columns(3)
|
152 |
+
with col1:
|
153 |
+
#st.image(ds[img]['image'],caption='Original Skin Lesion Image',use_column_width=True)
|
154 |
+
st.image(image_arr[img],caption='Original Skin Lesion Image',use_column_width=True)
|
155 |
+
with col2:
|
156 |
+
st.image(predicted_mask,caption='Predicted Mask',use_column_width=True)
|
157 |
+
with col3:
|
158 |
+
st.image(result_image,caption='Mask Overlay',use_column_width=True)
|
159 |
+
with tab2:
|
160 |
+
#st.write(f'The IOU Score: {iou_calculation(ds[img]["label"],predicted_mask)}')
|
161 |
+
#st.write(f'The Pixel Accuracy: {calculate_pixel_accuracy(ds[img]["label"],predicted_mask)}')
|
162 |
+
#st.write(f'The Dice Coefficient Score: {calculate_dice_coefficient(ds[img]["label"],predicted_mask)}')
|
163 |
+
st.write(f'The IOU Score: {iou_calculation(label_arr[img],predicted_mask)}')
|
164 |
+
st.write(f'The Pixel Accuracy: {calculate_pixel_accuracy(label_arr[img],predicted_mask)}')
|
165 |
+
st.write(f'The Dice Coefficient Score: {calculate_dice_coefficient(label_arr[img],predicted_mask)}')
|