DLBot commited on
Commit
ec54fd7
·
verified ·
1 Parent(s): b2ae538

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -41
app.py CHANGED
@@ -85,52 +85,50 @@ def get_tiles(img, mode=0):
85
  result.append({'img':img3[i], 'idx':i})
86
  return result, n_tiles_with_info >= n_tiles
87
 
88
- def getitem(img,tile_mode):
89
- sub_imgs=False
90
-
91
- tiff_file = img
92
- image = skimage.io.MultiImage(tiff_file)[0]
93
- tiles, OK = get_tiles(image, tile_mode)
94
-
95
- idxes=n_tiles
96
- idxes = np.asarray(idxes)
97
- idxes=np.random.choice(list(range(n_tiles)),n_tiles, replace=False)
98
-
99
- n_row_tiles = int(np.sqrt(n_tiles))
100
- images = np.zeros((image_size * n_row_tiles, image_size * n_row_tiles, 3))
101
- for h in range(n_row_tiles):
102
- for w in range(n_row_tiles):
103
- i = h * n_row_tiles + w
104
-
105
- if len(tiles) > idxes[i]:
106
- this_img = tiles[idxes[i]]['img']
107
- else:
108
- this_img = np.ones((image_size, image_size, 3)).astype(np.uint8) * 255
109
- this_img = 255 - this_img
110
- h1 = h * image_size
111
- w1 = w * image_size
112
- images[h1:h1+image_size, w1:w1+image_size] = this_img
113
-
114
- # images = 255 - images
115
- images = images.astype(np.float32)
116
- images /= 255
117
- images = images.transpose(2, 0, 1)
118
-
119
- return torch.tensor(images)
120
  def predict_label(im):
121
- data1=getitem(im,0)
122
- data2=getitem(im,2)
123
- LOGITS=[]
124
- LOGITS2=[]
 
125
  with torch.no_grad():
126
  data1 = data1.to(device)
127
  logits = models[0](data1)
128
  LOGITS.append(logits)
129
 
130
-
131
- data = data.to(device)
132
- logits = models[0](data)
133
- LOGITS2.append(logits)
134
 
135
  LOGITS = (torch.cat(LOGITS).sigmoid().cpu() + torch.cat(LOGITS2).sigmoid().cpu()) / 2
136
  PREDS = LOGITS.sum(1).round().numpy()
@@ -138,7 +136,6 @@ def predict_label(im):
138
 
139
 
140
 
141
-
142
  def classify_images(im):
143
  pred,idx,probs=predict_label(im)
144
  s='Your submitted case has Prostate cancer of ISUP Grade '+pred
 
85
  result.append({'img':img3[i], 'idx':i})
86
  return result, n_tiles_with_info >= n_tiles
87
 
88
+ def getitem(img, tile_mode):
89
+ tiff_file = img
90
+ image = skimage.io.MultiImage(tiff_file)[0]
91
+ tiles, OK = get_tiles(image, tile_mode)
92
+
93
+ idxes = np.random.choice(list(range(n_tiles)), n_tiles, replace=False)
94
+
95
+ n_row_tiles = int(np.sqrt(n_tiles))
96
+ images = np.zeros((image_size * n_row_tiles, image_size * n_row_tiles, 3))
97
+ for h in range(n_row_tiles):
98
+ for w in range(n_row_tiles):
99
+ i = h * n_row_tiles + w
100
+
101
+ if len(tiles) > idxes[i]:
102
+ this_img = tiles[idxes[i]]['img']
103
+ else:
104
+ this_img = np.ones((image_size, image_size, 3)).astype(np.uint8) * 255
105
+ this_img = 255 - this_img
106
+ h1 = h * image_size
107
+ w1 = w * image_size
108
+ images[h1:h1 + image_size, w1:w1 + image_size] = this_img
109
+
110
+ images = images.astype(np.float32)
111
+ images /= 255
112
+ images = images.transpose(2, 0, 1)
113
+
114
+ # Add a batch dimension
115
+ return torch.tensor(images).unsqueeze(0)
116
+
117
+
 
 
118
  def predict_label(im):
119
+ data1 = getitem(im, 0)
120
+ data2 = getitem(im, 2)
121
+ LOGITS = []
122
+ LOGITS2 = []
123
+
124
  with torch.no_grad():
125
  data1 = data1.to(device)
126
  logits = models[0](data1)
127
  LOGITS.append(logits)
128
 
129
+ data2 = data2.to(device)
130
+ logits2 = models[0](data2)
131
+ LOGITS2.append(logits2)
 
132
 
133
  LOGITS = (torch.cat(LOGITS).sigmoid().cpu() + torch.cat(LOGITS2).sigmoid().cpu()) / 2
134
  PREDS = LOGITS.sum(1).round().numpy()
 
136
 
137
 
138
 
 
139
  def classify_images(im):
140
  pred,idx,probs=predict_label(im)
141
  s='Your submitted case has Prostate cancer of ISUP Grade '+pred