Update app.py
Browse files84 unmodified lines8586878889909192939495969798991001011021031041051061071081091101111121131141151161171181198889909192939495969798991001011021031041051061071081091101111121131141151161171181211221231241191201211221231241251261271281301311321331291301311321331341 unmodified line13613713814113914014184 unmodified lines result.append({'img':img3[i], 'idx':i}) return result, n_tiles_with_info >= n_tiles
def getitem(img,tile_mode): sub_imgs=False tiff_file = img image = skimage.io.MultiImage(tiff_file)[0] tiles, OK = get_tiles(image, tile_mode)
idxes=n_tiles idxes = np.asarray(idxes) idxes=np.random.choice(list(range(n_tiles)),n_tiles, replace=False)
n_row_tiles = int(np.sqrt(n_tiles)) images = np.zeros((image_size * n_row_tiles, image_size * n_row_tiles, 3)) for h in range(n_row_tiles): for w in range(n_row_tiles): i = h * n_row_tiles + w if len(tiles) > idxes[i]: this_img = tiles[idxes[i]]['img'] else: this_img = np.ones((image_size, image_size, 3)).astype(np.uint8) * 255 this_img = 255 - this_img h1 = h * image_size w1 = w * image_size images[h1:h1+image_size, w1:w1+image_size] = this_img
# images = 255 - images images = images.astype(np.float32) images /= 255 images = images.transpose(2, 0, 1)
return torch.tensor(images)def getitem(img, tile_mode): tiff_file = img image = skimage.io.MultiImage(tiff_file)[0] tiles, OK = get_tiles(image, tile_mode)
idxes = np.random.choice(list(range(n_tiles)), n_tiles, replace=False)
n_row_tiles = int(np.sqrt(n_tiles)) images = np.zeros((image_size * n_row_tiles, image_size * n_row_tiles, 3)) for h in range(n_row_tiles): for w in range(n_row_tiles): i = h * n_row_tiles + w
if len(tiles) > idxes[i]: this_img = tiles[idxes[i]]['img'] else: this_img = np.ones((image_size, image_size, 3)).astype(np.uint8) * 255 this_img = 255 - this_img h1 = h * image_size w1 = w * image_size images[h1:h1 + image_size, w1:w1 + image_size] = this_img
images = images.astype(np.float32) images /= 255 images = images.transpose(2, 0, 1)
# Add a batch dimension return torch.tensor(images).unsqueeze(0)
def predict_label(im): data1=getitem(im,0) data2=getitem(im,2) LOGITS=[] LOGITS2=[] data1 = getitem(im, 0) data2 = getitem(im, 2) LOGITS = [] LOGITS2 = []
with torch.no_grad(): data1 = data1.to(device) logits = models[0](data1) LOGITS.append(logits)
data = data.to(device) logits = models[0](data) LOGITS2.append(logits) data2 = data2.to(device) logits2 = models[0](data2) LOGITS2.append(logits2)
LOGITS = (torch.cat(LOGITS).sigmoid().cpu() + torch.cat(LOGITS2).sigmoid().cpu()) / 2 PREDS = LOGITS.sum(1).round().numpy()1 unmodified line
def classify_images(im): pred,idx,probs=predict_label(im) s='Your submitted case has Prostate cancer of ISUP Grade '+predapp.py+38-41