forked from HelioStrike/kmit-cadsc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged lymphnode and mammo pipelines
- Loading branch information
1 parent
02b35f0
commit fe4ebe1
Showing
102 changed files
with
600 additions
and
66 deletions.
There are no files selected for viewing
Binary file modified
BIN
+0 Bytes
(100%)
pipelines/epithelium_segmentation/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
|
||
from fastai.vision import * | ||
from fastai.metrics import error_rate | ||
import numpy as np | ||
import random | ||
import h5py | ||
import cv2 as cv2 | ||
import os | ||
|
||
train_dir="./pipelines/lymph_node/data/data_bunch" | ||
base_dir="./pipelines/lymph_node/data" #base directory | ||
|
||
|
||
l=os.listdir(train_dir) | ||
random.shuffle(l) #shuffle training images | ||
|
||
|
||
|
||
|
||
|
||
tfms = get_transforms(do_flip=True) #do_flip: if True, a random flip is applied with probability 0.5 to images | ||
|
||
|
||
|
||
|
||
|
||
bs=64 # also the default batch size | ||
data = ImageDataBunch.from_csv( | ||
base_dir, | ||
ds_tfms=tfms, | ||
size=224, | ||
suffix=".tif", | ||
folder="data_bunch", | ||
#csv_labels="train_labels.csv", | ||
csv_labels="dummy_labels.csv", | ||
bs=bs) | ||
#ImageDataBunch splits out the imnages (in the train sub-folder) into a training set and validation set (defaulting to an 80/20 percent split) | ||
|
||
|
||
|
||
|
||
|
||
data.normalize(imagenet_stats) | ||
# transform the image values according to the nueral network we are using | ||
|
||
|
||
|
||
|
||
|
||
learn = cnn_learner(data,models.densenet161, metrics=error_rate, callback_fns=ShowGraph) | ||
#cnn_learner loads the model into learn variable` | ||
|
||
|
||
|
||
|
||
|
||
|
||
f2 = h5py.File("./pipelines/lymph_node_backend/camelyonpatch_level_2_split_test_y.h5", 'r') | ||
set2 = f2['y'] | ||
|
||
|
||
|
||
|
||
|
||
learn=learn.load("./pipelines/lymph_node/model/densenet10epochs.pth") | ||
|
||
|
||
|
||
|
||
import matplotlib.pyplot as plt | ||
|
||
|
||
image=orig | ||
actual=image | ||
preds=learn.predict(actual) | ||
r=int(preds[0]) | ||
fig = plt.figure() | ||
fig.set_figheight(3) | ||
fig.set_figwidth(3) | ||
if(set2[i][0][0][0]==0): | ||
actualresult="Normal" | ||
else: | ||
actualresult="Metastatic" | ||
if(r==0): | ||
result="Normal" | ||
else: | ||
result="Metastatic" | ||
plt.imshow(color) | ||
plt.show() | ||
print("Predicted Percentages") | ||
print("Normal:",float(preds[2][0])*100,"%","Metastatic:",float(preds[2][1])*100,"%") | ||
print("\n") | ||
print("Ground Truth:",actualresult) | ||
print("Predicted:",result) | ||
|
||
|
||
if(result==set2[i][0][0][0]): | ||
c=c+1 | ||
|
||
|
||
# In[16]: | ||
|
||
|
||
actual=open_image("/home/abhay/environments/histopathologic-cancer-detection/new_histotest/"+"0.tiff") | ||
predict=learn.predict(actual) | ||
|
||
|
||
# In[17]: | ||
|
||
|
||
predict | ||
|
||
|
||
# In[20]: | ||
|
||
|
||
float(predict[2][0])*100 | ||
|
||
|
||
# In[ ]: | ||
|
||
|
||
print("Testing Accuracy") | ||
print((c/32768)*100) | ||
|
||
|
||
# In[ ]: | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from __future__ import print_function | ||
import numpy as np | ||
from PIL import Image | ||
from fastai.vision import * | ||
from fastai.metrics import error_rate | ||
import cv2 | ||
import os | ||
import matplotlib.pyplot as plt | ||
import random | ||
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas | ||
import h5py | ||
from fastai.vision.transform import get_transforms | ||
from fastai.vision.data import ImageDataBunch | ||
from fastai.vision.image import pil2tensor | ||
|
||
|
||
MODEL_PATH = './pipelines/lymph_node_backend/data/densenet10epochs.pth' | ||
|
||
|
||
def preprocess(image_location): | ||
images=[] | ||
for location in image_location: | ||
img=cv2.imread(location) | ||
print("location ",location) | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_TRUNC) #applying truncation | ||
rgb = np.repeat(thresh[..., np.newaxis], 3, -1) | ||
print("type ",type(rgb)) | ||
images.append((Image(pil2tensor(rgb,dtype=np.float32).div_(255)))) | ||
print("tensor ",type(Image(pil2tensor(rgb,dtype=np.float32).div_(255)))) | ||
return images | ||
|
||
def predict(images): | ||
#loadig model | ||
train_dir="./pipelines/lymph_node/data/data_bunch" | ||
base_dir="./pipelines/lymph_node/data" #base directory | ||
l=os.listdir(train_dir) | ||
#random.shuffle(l) | ||
tfms = get_transforms(do_flip=True) | ||
#do_flip: if True, a random flip is applied with probability 0.5 to images | ||
bs=64 # also the default batch size | ||
print("loaddd") | ||
#ImageDataBunch splits out the imnages (in the train sub-folder) into a training set and validation set (defaulting to an 80/20 percent split) | ||
data = ImageDataBunch.from_csv(base_dir, ds_tfms=tfms, size=224, suffix=".tiff",folder="data_bunch",csv_labels="dummy_labels.csv", bs=bs) | ||
print("valid ",data.valid_ds) | ||
print("train ",data.train_ds) | ||
print("test ",data.test_ds) | ||
# transform the image values according to the nueral network we are using | ||
data.normalize(imagenet_stats) | ||
|
||
#cnn_learner loads the model into learn variable` | ||
learn = cnn_learner(data,models.densenet161, metrics=error_rate, callback_fns=ShowGraph) | ||
|
||
|
||
|
||
learn=learn.load("./densenet10epochs") | ||
#predicting labels | ||
print("prediction ",type(images)) | ||
print(images) | ||
print("size ",len(images),images[0].shape) | ||
preds=learn.predict(images[0]) | ||
#preds=learn.pred_batch(np.array(images)) #TO-DO!!!!!!!! | ||
print(type(preds)) | ||
print("prediction ",preds) | ||
return preds | ||
|
||
|
||
|
||
|
||
|
||
|
||
#pass in the original , and get the image to be displayed on the website | ||
def get_display_image(orig): | ||
#preprocessing | ||
print(type(orig)) | ||
print("def init LOCCCCCC",orig) | ||
preprocessed=preprocess(orig) | ||
preds=predict(preprocessed) | ||
print(preds) | ||
fh = 30 | ||
fw = 15 | ||
f2 = h5py.File("./pipelines/lymph_node/data/camelyonpatch_level_2_split_test_y.h5", 'r') #contains actuals test labels | ||
set2 = f2['y'] | ||
print(len(set2)) | ||
imgs = [orig,preds] | ||
titles = ['Image', 'Normal', 'Metastatic','actual'] | ||
f, ax = plt.subplots(len(orig), 4 , figsize=(fh,fw)) | ||
print(preds[0]) | ||
for i in range(len(orig)): | ||
print(preds[0]) | ||
r=int(preds[0]) | ||
print("rrrrrrr ",r) | ||
"""fig = plt.figure() | ||
fig.set_figheight(3) | ||
fig.set_figwidth(3)""" | ||
image_name=orig[i].split("/") | ||
val=image_name[1].split(".") | ||
print("val ",val) | ||
print(set2) | ||
ans="" | ||
|
||
if(set2[(int)(val[0])][0][0][0]==0): | ||
actualresult="Normal" | ||
else: | ||
actualresult="Metastatic" | ||
if(r==0): | ||
result="Normal" | ||
else: | ||
result="Metastatic" | ||
#plt.imshow(cv2.imread(orig[i])) | ||
#plt.show() | ||
m1=str(round(float(preds[2][1])*100,2)) | ||
m2=str(round(float(preds[2][0])*100,2)) | ||
ans=actualresult+" "+"Metastatic"+m1+" "+"Normal"+m2 | ||
print(ans) | ||
"""print("Predicted Percentages") | ||
print("Normal:",float(preds[2][0])*100,"%","Metastatic:",float(preds[2][1])*100,"%") | ||
print("\n") | ||
print("Ground Truth:",actualresult) | ||
print("Predicted:",result)""" | ||
|
||
return ans | ||
|
||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
0,0 | ||
1,1 | ||
2,0 | ||
3,1 | ||
4,1 | ||
5,0 | ||
6,1 | ||
7,1 | ||
8,1 | ||
9,0 | ||
10,1 | ||
11,0 | ||
12,1 | ||
13,1 | ||
14,0 | ||
15,1 | ||
16,0 | ||
17,1 | ||
69,1 | ||
70,1 | ||
71,0 | ||
72,0 | ||
73,0 | ||
74,1 | ||
75,1 | ||
76,1 | ||
77,1 | ||
78,1 | ||
79,1 | ||
80,1 | ||
81,0 | ||
82,1 | ||
83,1 | ||
84,1 | ||
85,1 | ||
99,0 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+621 Bytes
(100%)
pipelines/mammography/__pycache__/frcnn_test_vgg.cpython-37.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mdb012.png,431,526,511,606,B | ||
mdb265.png,533,466,653,586,M | ||
mdb290.png,292,626,382,716,B | ||
mdb314.png,479,794,557,872,B | ||
mdb069.png,418,574,506,662,B | ||
mdb144.png,286,457,340,511,M | ||
mdb075.png,445,284,491,330,M | ||
mdb025.png,595,502,753,660,B | ||
mdb142.png,321,362,373,414,B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.