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
def __getitem__(self, idx): | |
if torch.is_tensor(idx): | |
idx = idx.tolist() | |
repeat = True | |
while(repeat): | |
try: | |
path = self.directories[idx] |
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
class MRIDataset(Dataset): | |
def __init__(self, root_dir, labels, transform=None): | |
self.root_dir = root_dir | |
self.transform = transform | |
self.directories = [] | |
self.len = 0 | |
self.labels = labels | |
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
sMCI_df = clin[clin["label"] == "sMCI"] | |
pMCI_df = clin[clin["label"] == "pMCI"] | |
kde_kws = {"color": "orange", "lw": 2, "label": "sMCI", "shade":True} | |
sns.distplot(sMCI_df["AGE"], kde_kws=kde_kws, hist=False) | |
kde_kws = {"color": "red", "lw": 2, "label": "pMCI", "shade":True} | |
sns.distplot(pMCI_df["AGE"], color="magenta", kde_kws=kde_kws, hist=False) |
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
import seaborn as sns | |
import pandas as pd | |
import matplotlib as plt | |
clin = pd.read_csv("./bas_clin_with_categorical.csv") | |
clin.head() |
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
out_a = self.stack3_a(out_a) | |
out_b = self.stack3_b(out_b) | |
out = torch.cat((out_a, out_b), 1) |
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
identity = out | |
out = self.layer(out) | |
out = out + identity |
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
class ConvBlock(nn.Module): | |
def __init__(self, c_in, c_out, ks, k_stride=1): | |
super().__init__() | |
self.conv1 = nn.Conv3d(c_in, c_out, ks, stride=k_stride, padding=(1,1,1)) | |
self.bn = nn.BatchNorm3d(c_out) | |
self.elu = nn.ELU() | |
self.pool = nn.MaxPool3d(kernel_size=(3,3,3), stride=2) |
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
import matplotlib.pyplot as plt | |
import nibabel as nib | |
def show_image(image): | |
plt.imshow(image) | |
fig = plt.figure() | |
mri = nib.load("path_to_mri_scan\\mri_volume.nii").get_fdata() | |
mri.shape |
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
def X_Y_df_split(in_df): | |
X_df = in_df.drop(columns=['fun', 'valuable', 'exciting', 'awesome', 'cool'], axis=1) | |
Y_df = in_df.drop(columns=['id', 'comment_text'], axis=1) | |
return (X_df, Y_df) |