Skip to content

Commit

Permalink
fix evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
bofei5675 committed Feb 4, 2020
1 parent 279fc2e commit 6c08336
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
84 changes: 40 additions & 44 deletions oai-knee-detection/dataset_generation/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,52 @@
import pandas as pd
import numpy as np
import os
import time
import sys
import h5py
from tqdm import tqdm
import scipy.ndimage as ndimage
import argparse

'''
This file used new pipeline to get images preprocessed.
'''
MONTH = str(sys.argv[1])
df = pd.read_csv('../output_data/output{}.csv'.format(MONTH))
output_folder = '/gpfs/data/denizlab/Users/bz1030/KneeNet/KneeProject/test/bbox_prepprocessing'
save_dir ='/gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new3'
if not os.path.exists(output_folder):
os.makedirs(output_folder)
bar = tqdm(total=df.shape[0], desc='Processing', ncols=90)
parser = argparse.ArgumentParser(description='Annotation')
parser.add_argument('-m', '--month', action="store", dest="month", type=str,
help='month file for OAI e.g. 00m 12m 24m etc.', default=None)
parser.add_argument('-md', '--model-dir', type=str, dest='model_dir',
default='../model_weights/KneeJointLocalModel/resnet18_detector.pth')
parser.add_argument('-sd', '--save-dir', action="store", dest="save_dir", type=str,
help="where you want to save after conversion from DICOM to H5",
default='../data/OAI_processed/')
def main():
args = parser.parse_args()
Month = args.month
df = pd.read_csv('../output_data/output{}.csv'.format(MONTH))
output_folder = '../data/bbox_prepprocessing'
save_dir ='../data/OAI_processed_new3'
if not os.path.exists(output_folder):
os.makedirs(output_folder)
bar = tqdm(total=df.shape[0], desc='Processing', ncols=90)

for idx, row in df.iterrows():
row = row.tolist()
data_path = row[-1]
data_path = data_path.replace('//','/')
month = data_path.split('/')[-6]
p_id = data_path.split('/')[-4]
print(month,p_id)
bbox = np.array(row[:8])
img, data, img_before = image_preprocessing(data_path)
left,right = getKneeWithBbox(img,bbox)
f_name_l = '{}_{}_LEFT_KNEE.hdf5'.format(p_id,month)
f_name_r = '{}_{}_RIGHT_KNEE.hdf5'.format(p_id,month)
print(f_name_l,f_name_r)
path2save = os.path.join(save_dir,month)
print(left.shape,right.shape)
left, _, _ = padding(left, img_size=(1024,1024))
right, _, _ = padding(right, img_size=(1024,1024))
create_h5(path2save,f_name_l,left)
create_h5(path2save, f_name_r, right)
bar.update(1)
for idx, row in df.iterrows():
row = row.tolist()
data_path = row[-1]
data_path = data_path.replace('//','/')
month = data_path.split('/')[-6]
p_id = data_path.split('/')[-4]
print(month,p_id)
bbox = np.array(row[:8])
img, data, img_before = image_preprocessing(data_path)
left,right = getKneeWithBbox(img,bbox)
f_name_l = '{}_{}_LEFT_KNEE.hdf5'.format(p_id,month)
f_name_r = '{}_{}_RIGHT_KNEE.hdf5'.format(p_id,month)
print(f_name_l,f_name_r)
path2save = os.path.join(save_dir,month)
print(left.shape,right.shape)
left, _, _ = padding(left, img_size=(1024,1024))
right, _, _ = padding(right, img_size=(1024,1024))
create_h5(path2save,f_name_l,left)
create_h5(path2save, f_name_r, right)
bar.update(1)


''' to display the data
for idx, row in df.iterrows():
row = row.tolist()
data_path = row[-1]
data_path = data_path.replace('//','/')
bbox = np.array(row[:8])
img, data, img_before = image_preprocessing(data_path)
f_name = data_path
f_name = f_name.split('/')[-6:-1]
f_name = '_'.join(f_name) + '.png'
drawKneeWithBbox(img,bbox,output_folder,f_name)
print(data_path)
'''
if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion oai-knee-detection/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
default='../model_weights/ResNet18_/epoch_45.pth')
parser.add_argument('-cd', '--content-dir', action="store", dest="content_dir", type=str,
help="content file", default='../data/OAI_summary.csv')
# place the original OAI dataset (DICOM file) in the data home directory
parser.add_argument('-dh', '--data-home', action="store", dest="data_home", type=str,
help="data home directory", default='/gpfs/data/denizlab/Datasets/OAI_original')
help="data home directory", default='../data/OAI_original')
parser.add_argument('-m', '--month', action="store", dest="month", type=str,
help="which part of OAI to be processed", default='00m')
parser.add_argument('-nw', '--num-workers', action="store", dest="num_workers", type=int,
Expand Down
2 changes: 0 additions & 2 deletions oai-knee-detection/train_test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def main(args):
print(df.shape)

month = '00m'
#OAI_DATASET = '/gpfs/data/denizlab/Datasets/OAI_original'
OAI_DATASET = args.dataset
#output_folder = '/gpfs/data/denizlab/Users/bz1030/data/bounding_box/'
output_folder = args.output_dir
print(df.shape)
train = df.sample(frac=0.7)
Expand Down
11 changes: 8 additions & 3 deletions oai-xray-klg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ To reproduce the baseline ResNet experiment and ResNet with CBAM, please run the
```bash
python3 main.py -n baseline -m CBAM -do\
-au -ep 30 -lr 0.0001 -bs 6 -dm no\
-d /gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new4/\
-dc /gpfs/data/denizlab/Users/bz1030/data/OAI_proj15/
-d ../data/OAI_processed/\
-dc ../data/classifier/
```
Above code will get content file from `OAI_proj15` file and then load data from `OAI_processed_new4`. Arguments `-m` can have `baseline` or `CBAM` which stand for the experiments mentioned in paper. Please refer `./main.py` for description of other arguments.
Above code will get content file from `../data/classifier/` folder and then load data from `OAI_processed` obtained from detector step.
Arguments `-m` can have `baseline` or `CBAM` which stand for the experiments mentioned in paper. Please refer `./main.py` for description of other arguments.

To evaluate certain model after train and model selection by best performance on validation dataset. You can run:
```bash
python3 evaluate.py -lm ../model_weights/Classifier/best-model-baseline.pth -hd ../data/classifier/
```
To reproduce all attention heatmap, please run the following code
```bash
python3 attention_map.py -lm <model-weights> -hd <home-dir-where-you-saved-h5-files> -sp <summary-path>
Expand Down

0 comments on commit 6c08336

Please sign in to comment.