diff --git a/oai-knee-detection/dataset_generation/sanity_check.py b/oai-knee-detection/dataset_generation/sanity_check.py deleted file mode 100644 index ee51dce..0000000 --- a/oai-knee-detection/dataset_generation/sanity_check.py +++ /dev/null @@ -1,39 +0,0 @@ -from utils import * -import pandas as pd -import numpy as np -import os -import time -import sys -import h5py -from tqdm import tqdm -''' -This script checks if all images in OAI are in our dataset. -''' -df = pd.read_csv('/gpfs/data/denizlab/Users/bz1030/KneeNet/KneeProject/Dataset/OAI_summary.csv') -output_folder = '/gpfs/data/denizlab/Users/bz1030/KneeNet/KneeProject/test/bbox_prepprocessing' -save_dir ='/gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new' - -print(df.head()) -df = df[['ID','Visit']].drop_duplicates() -total_img = df.shape[0] * 2 -count = 0 -for idx,row in df.iterrows(): - p_id = row[0] - visit = row[1] - f_name_l = '{}_{}_LEFT_KNEE.hdf5'.format(p_id,visit) - f_name_r = '{}_{}_RIGHT_KNEE.hdf5'.format(p_id,visit) - f_name_l = os.path.join(save_dir,visit,f_name_l) - f_name_r = os.path.join(save_dir,visit,f_name_r) - if os.path.isfile(f_name_l): - count += 1 - else: - print('{} Not Found'.format(f_name_l)) - - if os.path.isfile(f_name_r): - count += 1 - else: - print('{} Not Found'.format(f_name_r)) - -print('Total image left: {}/{}'.format(count,total_img)) - - diff --git a/oai-xray-klg/attention_map.py b/oai-xray-klg/attention_map.py index fb80804..37069b1 100644 --- a/oai-xray-klg/attention_map.py +++ b/oai-xray-klg/attention_map.py @@ -21,20 +21,17 @@ parser = argparse.ArgumentParser() parser.add_argument('-lm', '--load-model', action='store', dest='load_model', default=None, type=str) +parser.add_argument('-hp', '--home-path', action='store', dest='home_path', + default=None, type=str, help='Path where you have all h5 file saved') +parser.add_argument('-sp', '--summary-path', action='store', dest='summary_path', + default=None, type=str, help='Path of dataloader file train.csv/val.csv/test.csv') if __name__ == '__main__': args = parser.parse_args() USE_CUDA = torch.cuda.is_available() device = torch.device("cuda" if USE_CUDA else "cpu") - job_number = int(1) -<<<<<<< HEAD - HOME_PATH = '/gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new4/' - summary_path = '/gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new4/' - test = pd.read_csv(summary_path + 'test_proj15.csv')#.sample(n=50).reset_index() # split train - test set. -======= - HOME_PATH = '/gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new3/' - summary_path = '/gpfs/data/denizlab/Users/bz1030/data/OAI_processed_new3/' - test = pd.read_csv(summary_path + 'test.csv')#.sample(n=50).reset_index() # split train - test set. ->>>>>>> 3daec0b3c4c24e2e7ea2c7d701ac6af1c7323480 + HOME_PATH = args.home_path + summary_path = args.summary_path + test = pd.read_csv(summary_path) start_test = 0 tensor_transform_test = transforms.Compose([ @@ -57,7 +54,7 @@ net.eval() print('############### Model Finished ####################') print(test.head()) - path_name = '/gpfs/data/denizlab/Users/bz1030/data/OAI_processed/mix' + path_name = args.home_path save_dir = '/'.join(args.load_model.split('/')[:-1] + ['attention_map']) for idx, row in test.iterrows(): month = row['Visit'] diff --git a/oai-xray-klg/attn_resnet/scripts/train_imagenet_resnet50_bam.sh b/oai-xray-klg/attn_resnet/scripts/train_imagenet_resnet50_bam.sh deleted file mode 100644 index aebe961..0000000 --- a/oai-xray-klg/attn_resnet/scripts/train_imagenet_resnet50_bam.sh +++ /dev/null @@ -1,9 +0,0 @@ -python train_imagenet.py \ - --ngpu 8 \ - --workers 20 \ - --arch resnet --depth 50 \ - --epochs 100 \ - --batch-size 256 --lr 0.1 \ - --att-type BAM \ - --prefix RESNET50_IMAGENET_BAM \ - ./data/ImageNet/ diff --git a/oai-xray-klg/attn_resnet/scripts/train_imagenet_resnet50_cbam.sh b/oai-xray-klg/attn_resnet/scripts/train_imagenet_resnet50_cbam.sh deleted file mode 100644 index 1f51b31..0000000 --- a/oai-xray-klg/attn_resnet/scripts/train_imagenet_resnet50_cbam.sh +++ /dev/null @@ -1,9 +0,0 @@ -python train_imagenet.py \ - --ngpu 8 \ - --workers 20 \ - --arch resnet --depth 50 \ - --epochs 100 \ - --batch-size 256 --lr 0.1 \ - --att-type CBAM \ - --prefix RESNET50_IMAGENET_CBAM \ - ./data/ImageNet/ diff --git a/oai-xray-klg/attn_resnet/wide_resnet/wide_resnet.py b/oai-xray-klg/attn_resnet/wide_resnet/wide_resnet.py deleted file mode 100644 index bfa16db..0000000 --- a/oai-xray-klg/attn_resnet/wide_resnet/wide_resnet.py +++ /dev/null @@ -1,86 +0,0 @@ -import math -import torch -import torch.nn as nn -import torch.nn.functional as F - - -class BasicBlock(nn.Module): - def __init__(self, in_planes, out_planes, stride, dropRate=0.0): - super(BasicBlock, self).__init__() - self.bn1 = nn.BatchNorm2d(in_planes) - self.relu1 = nn.ReLU(inplace=True) - self.conv1 = nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, - padding=1, bias=False) - self.bn2 = nn.BatchNorm2d(out_planes) - self.relu2 = nn.ReLU(inplace=True) - self.conv2 = nn.Conv2d(out_planes, out_planes, kernel_size=3, stride=1, - padding=1, bias=False) - self.droprate = dropRate - self.equalInOut = (in_planes == out_planes) - self.convShortcut = (not self.equalInOut) and nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, - padding=0, bias=False) or None - def forward(self, x): - if not self.equalInOut: - x = self.relu1(self.bn1(x)) - else: - out = self.relu1(self.bn1(x)) - out = self.relu2(self.bn2(self.conv1(out if self.equalInOut else x))) - if self.droprate > 0: - out = F.dropout(out, p=self.droprate, training=self.training) - out = self.conv2(out) - return torch.add(x if self.equalInOut else self.convShortcut(x), out) - -class NetworkBlock(nn.Module): - def __init__(self, nb_layers, in_planes, out_planes, block, stride, dropRate=0.0): - super(NetworkBlock, self).__init__() - self.layer = self._make_layer(block, in_planes, out_planes, nb_layers, stride, dropRate) - def _make_layer(self, block, in_planes, out_planes, nb_layers, stride, dropRate): - layers = [] - for i in range(int(nb_layers)): - layers.append(block(i == 0 and in_planes or out_planes, out_planes, i == 0 and stride or 1, dropRate)) - return nn.Sequential(*layers) - def forward(self, x): - return self.layer(x) - -class WideResNet(nn.Module): - def __init__(self, depth, num_classes, widen_factor=1, dropRate=0.0): - super(WideResNet, self).__init__() - nChannels = [16, 16*widen_factor, 32*widen_factor, 64*widen_factor] - assert((depth - 4) % 6 == 0) - n = (depth - 4) / 6 - block = BasicBlock - # 1st conv before any network block - self.conv1 = nn.Conv2d(3, nChannels[0], kernel_size=3, stride=1, - padding=1, bias=False) - # 1st block - self.block1 = NetworkBlock(n, nChannels[0], nChannels[1], block, 1, dropRate) - # 2nd block - self.block2 = NetworkBlock(n, nChannels[1], nChannels[2], block, 2, dropRate) - # 3rd block - self.block3 = NetworkBlock(n, nChannels[2], nChannels[3], block, 2, dropRate) - # global average pooling and classifier - self.bn1 = nn.BatchNorm2d(nChannels[3]) - self.relu = nn.ReLU(inplace=True) - self.fc = nn.Linear(nChannels[3], num_classes) - self.nChannels = nChannels[3] - - for m in self.modules(): - if isinstance(m, nn.Conv2d): - nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') - elif isinstance(m, nn.BatchNorm2d): - m.weight.data.fill_(1) - m.bias.data.zero_() - elif isinstance(m, nn.Linear): - m.bias.data.zero_() - def forward(self, x): - out = self.conv1(x) - out = self.block1(out) - out = self.block2(out) - out = self.block3(out) - out = self.relu(self.bn1(out)) - out = F.avg_pool2d(out, 8) - out = out.view(-1, self.nChannels) - return self.fc(out) - -model = WideResNet(args.layers, args.dataset == 'ImageNet' and 10 or 100, - args.widen_factor, dropRate=args.droprate) \ No newline at end of file