ahishamm commited on
Commit
7d984d9
1 Parent(s): 22e2d48

Updated app.py with new layout and new pictures

Browse files
Files changed (1) hide show
  1. app.py +38 -22
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[0]['image']
118
- s2 = ds[1]['image']
119
- s3 = ds[2]['image']
 
 
 
 
 
 
 
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
- p = get_bounding_box(np.array(ds[img]['label']))
132
- predicted_mask_array = get_output(ds[img]['image'],p)
 
 
 
 
133
  predicted_mask = generate_image(predicted_mask_array)
134
- result_image = show_mask(ds[img]['image'],predicted_mask_array)
 
135
  with st.container():
136
- col1, col2, col3 = st.columns(3)
137
- with col1:
138
- st.image(ds[img]['image'],caption='Original Skin Lesion Image',use_column_width=True)
139
- with col2:
140
- st.image(predicted_mask,caption='Predicted Mask',use_column_width=True)
141
- with col3:
142
- st.write(f'The IOU Score: {iou_calculation(ds[img]["label"],predicted_mask)}')
143
- st.write(f'The Pixel Accuracy: {calculate_pixel_accuracy(ds[img]["label"],predicted_mask)}')
144
- st.write(f'The Dice Coefficient Score: {calculate_dice_coefficient(ds[img]["label"],predicted_mask)}')
145
- with st.container():
146
- col4,col5,col6 = st.columns(3)
147
- with col5:
148
- st.image(result_image,caption='Mask Overlay',use_column_width=True)
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)}')