ahishamm commited on
Commit
87f6406
1 Parent(s): 7d984d9

Updated interface

Browse files
Files changed (1) hide show
  1. app.py +2 -16
app.py CHANGED
@@ -109,8 +109,6 @@ def calculate_dice_coefficient(image1, image2):
109
  false_negatives = np.sum(np.logical_and(np_image1_flat == 255, np_image2_flat != 255))
110
  dice_coefficient = (2 * true_positives) / (2 * true_positives + false_positives + false_negatives)
111
  return dice_coefficient
112
-
113
-
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')
@@ -132,34 +130,22 @@ img = image_select(
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)}')
 
109
  false_negatives = np.sum(np.logical_and(np_image1_flat == 255, np_image2_flat != 255))
110
  dice_coefficient = (2 * true_positives) / (2 * true_positives + false_positives + false_negatives)
111
  return dice_coefficient
 
 
112
  device = "cuda" if torch.cuda.is_available() else "cpu"
113
  st.set_page_config(layout='wide')
114
  ds = load_dataset('ahishamm/combined_masks',split='train')
 
130
  captions=["sample 1","sample 2","sample 3","sample 4"],
131
  return_value='index'
132
  )
 
133
  processor = AutoProcessor.from_pretrained('ahishamm/skinsam')
134
  model = AutoModelForMaskGeneration.from_pretrained('ahishamm/skinsam_focalloss_base_combined')
135
  model.to(device)
 
 
136
  p = get_bounding_box(np.array(label_arr[img]))
 
137
  predicted_mask_array = get_output(image_arr[img],p)
 
138
  predicted_mask = generate_image(predicted_mask_array)
 
139
  result_image = show_mask(image_arr[img],predicted_mask_array)
140
  with st.container():
141
  tab1, tab2 = st.tabs(['Visualizations','Metrics'])
142
  with tab1:
143
+ col1, col2 = st.columns(2)
144
  with col1:
 
145
  st.image(image_arr[img],caption='Original Skin Lesion Image',use_column_width=True)
146
+ with col2:
 
 
147
  st.image(result_image,caption='Mask Overlay',use_column_width=True)
148
  with tab2:
 
 
 
149
  st.write(f'The IOU Score: {iou_calculation(label_arr[img],predicted_mask)}')
150
  st.write(f'The Pixel Accuracy: {calculate_pixel_accuracy(label_arr[img],predicted_mask)}')
151
  st.write(f'The Dice Coefficient Score: {calculate_dice_coefficient(label_arr[img],predicted_mask)}')